Skip to content

Commit

Permalink
Added DBIO alias type
Browse files Browse the repository at this point in the history
  • Loading branch information
takapi327 committed Dec 24, 2024
1 parent 4fdefc4 commit a1f900f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
3 changes: 1 addition & 2 deletions module/ldbc-dsl/src/main/scala/ldbc/dsl/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ package object dsl:
def orderByOpt(s1: Option[SQL], s2: Option[SQL], ss: Option[SQL]*): Mysql[F] =
orderByOpt((s1 :: s2 :: ss.toList).flatten)

// type DBIO[T] = ldbc.dsl.DBIO[F, T]
export ldbc.dsl.DBIO
type DBIO[T] = ldbc.dsl.DBIO[F, T]

export ldbc.dsl.logging.LogHandler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ package object syntax:
case _ => DslQuery.Impl[F, P](query.statement, query.params, Decoder.derivedProduct(m1))

extension (command: Command)
def update: DBIO[F, Int] =
def update: DBIO[Int] =
DBIO.Impl[F, Int](
command.statement,
command.params,
Expand All @@ -55,7 +55,7 @@ package object syntax:
yield result
)

def returning[T <: String | Int | Long](using decoder: Decoder.Elem[T]): DBIO[F, T] =
def returning[T <: String | Int | Long](using decoder: Decoder.Elem[T]): DBIO[T] =
given Decoder[T] = Decoder.one[T]

DBIO.Impl[F, T](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ class QuerySyntaxTest extends AnyFlatSpec:
assertCompiles(
"""
|import cats.effect.IO
|import ldbc.dsl.DBIO
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
|case class User(id: Long, name: String, age: Int) derives Table
|
|val user = TableQuery[User]
|
|val query: Executor[IO, List[User]] = user.selectAll.query.to[List]
|val query: DBIO[List[User]] = user.selectAll.query.to[List]
|""".stripMargin
)
}
Expand Down Expand Up @@ -94,15 +93,14 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
|case class User(id: Long, name: String, age: Int) derives Table
|
|val user = TableQuery[User]
|
|val query: Executor[IO, Option[User]] = user.selectAll.where(_.id === 1).query.to[Option]
|val query: DBIO[Option[User]] = user.selectAll.where(_.id === 1).query.to[Option]
|""".stripMargin
)
}
Expand All @@ -112,15 +110,14 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
|case class User(id: Long, name: String, age: Int) derives Table
|
|val user = TableQuery[User]
|
|val query: Executor[IO, User] = user.selectAll.where(_.id === 1).query.unsafe
|val query: DBIO[User] = user.selectAll.where(_.id === 1).query.unsafe
|""".stripMargin
)
}
Expand All @@ -146,15 +143,14 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
|case class User(id: Long, name: String, age: Int) derives Table
|
|val user = TableQuery[User]
|
|val query: Executor[IO, User] = user.selectAll.where(_.id === 1).query.unsafe
|val query: DBIO[User] = user.selectAll.where(_.id === 1).query.unsafe
|""".stripMargin
)
}
Expand All @@ -164,7 +160,6 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
Expand All @@ -177,7 +172,7 @@ class QuerySyntaxTest extends AnyFlatSpec:
|
|case class UserCategory(userName: String, categoryName: String)
|
|val query: Executor[IO, List[(String, String)]] = (user join category).on((user, category) => user.categoryId === category.id)
|val query: DBIO[List[(String, String)]] = (user join category).on((user, category) => user.categoryId === category.id)
| .select((user, category) => user.name *: category.name)
| .query
| .to[List]
Expand All @@ -190,7 +185,6 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
Expand All @@ -216,7 +210,6 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
Expand All @@ -233,7 +226,7 @@ class QuerySyntaxTest extends AnyFlatSpec:
|val cityQuery = TableQuery[City]
|val countryLanguageQuery = TableQuery[CountryLanguage]
|
|val query: Executor[IO, List[(String, String, Option[String])]] = (countryQuery join cityQuery).on((country, city) => country.code === city.countryCode)
|val query: DBIO[List[(String, String, Option[String])]] = (countryQuery join cityQuery).on((country, city) => country.code === city.countryCode)
| .leftJoin(countryLanguageQuery).on((_, city, countryLanguage) => city.countryCode === countryLanguage.countryCode)
| .select((country, city, countryLanguage) => country.name *: city.name *: countryLanguage.language)
| .query
Expand All @@ -247,7 +240,6 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
Expand All @@ -264,7 +256,7 @@ class QuerySyntaxTest extends AnyFlatSpec:
|val cityQuery = TableQuery[City]
|val countryLanguageQuery = TableQuery[CountryLanguage]
|
|val query: Executor[IO, List[(Option[String], Option[String], String)]] = (countryQuery join cityQuery).on((country, city) => country.code === city.countryCode)
|val query: DBIO[List[(Option[String], Option[String], String)]] = (countryQuery join cityQuery).on((country, city) => country.code === city.countryCode)
| .rightJoin(countryLanguageQuery).on((_, city, countryLanguage) => city.countryCode === countryLanguage.countryCode)
| .select((country, city, countryLanguage) => country.name *: city.name *: countryLanguage.language)
| .query
Expand All @@ -278,7 +270,6 @@ class QuerySyntaxTest extends AnyFlatSpec:
"""
|import cats.effect.IO
|
|import ldbc.dsl.Executor
|import ldbc.query.builder.Table
|import ldbc.query.builder.syntax.io.*
|
Expand All @@ -295,7 +286,7 @@ class QuerySyntaxTest extends AnyFlatSpec:
|val cityQuery = TableQuery[City]
|val countryLanguageQuery = TableQuery[CountryLanguage]
|
|val query: Executor[IO, List[(String, String, Option[String])]] = (countryQuery join cityQuery).on((country, city) => country.code === city.countryCode)
|val query: DBIO[List[(String, String, Option[String])]] = (countryQuery join cityQuery).on((country, city) => country.code === city.countryCode)
| .leftJoin(countryLanguageQuery).on((_, city, countryLanguage) => city.countryCode === countryLanguage.countryCode)
| .select((country, city, countryLanguage) => country.name *: city.name *: countryLanguage.language)
| .query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ package object syntax:
case _ => DslQuery.Impl[F, P](query.statement, query.params, Decoder.derivedProduct(m1))

extension (command: Command)
def update: DBIO[F, Int] =
def update: DBIO[Int] =
DBIO.Impl[F, Int](
command.statement,
command.params,
Expand All @@ -52,7 +52,7 @@ package object syntax:
yield result
)

def returning[T <: String | Int | Long](using decoder: Decoder.Elem[T]): DBIO[F, T] =
def returning[T <: String | Int | Long](using decoder: Decoder.Elem[T]): DBIO[T] =
given Decoder[T] = Decoder.one[T]

DBIO.Impl[F, T](
Expand Down

0 comments on commit a1f900f

Please sign in to comment.