From a1f900fb5f02e6405eb516303aa7ad539b3f82b8 Mon Sep 17 00:00:00 2001 From: takapi327 Date: Tue, 24 Dec 2024 21:14:07 +0900 Subject: [PATCH] Added DBIO alias type --- .../src/main/scala/ldbc/dsl/package.scala | 3 +-- .../ldbc/query/builder/syntax/package.scala | 4 +-- .../ldbc/query/builder/QuerySyntaxTest.scala | 25 ++++++------------- .../scala/ldbc/schema/syntax/package.scala | 4 +-- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/module/ldbc-dsl/src/main/scala/ldbc/dsl/package.scala b/module/ldbc-dsl/src/main/scala/ldbc/dsl/package.scala index b63bf8b5c..74969f7da 100644 --- a/module/ldbc-dsl/src/main/scala/ldbc/dsl/package.scala +++ b/module/ldbc-dsl/src/main/scala/ldbc/dsl/package.scala @@ -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 diff --git a/module/ldbc-query-builder/src/main/scala/ldbc/query/builder/syntax/package.scala b/module/ldbc-query-builder/src/main/scala/ldbc/query/builder/syntax/package.scala index 99ff2f0ea..fea69638e 100644 --- a/module/ldbc-query-builder/src/main/scala/ldbc/query/builder/syntax/package.scala +++ b/module/ldbc-query-builder/src/main/scala/ldbc/query/builder/syntax/package.scala @@ -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, @@ -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]( diff --git a/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/QuerySyntaxTest.scala b/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/QuerySyntaxTest.scala index 63ab54188..2a33aa327 100644 --- a/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/QuerySyntaxTest.scala +++ b/module/ldbc-query-builder/src/test/scala/ldbc/query/builder/QuerySyntaxTest.scala @@ -45,7 +45,6 @@ class QuerySyntaxTest extends AnyFlatSpec: assertCompiles( """ |import cats.effect.IO - |import ldbc.dsl.DBIO |import ldbc.query.builder.Table |import ldbc.query.builder.syntax.io.* | @@ -53,7 +52,7 @@ class QuerySyntaxTest extends AnyFlatSpec: | |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 ) } @@ -94,7 +93,6 @@ class QuerySyntaxTest extends AnyFlatSpec: """ |import cats.effect.IO | - |import ldbc.dsl.Executor |import ldbc.query.builder.Table |import ldbc.query.builder.syntax.io.* | @@ -102,7 +100,7 @@ class QuerySyntaxTest extends AnyFlatSpec: | |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 ) } @@ -112,7 +110,6 @@ class QuerySyntaxTest extends AnyFlatSpec: """ |import cats.effect.IO | - |import ldbc.dsl.Executor |import ldbc.query.builder.Table |import ldbc.query.builder.syntax.io.* | @@ -120,7 +117,7 @@ class QuerySyntaxTest extends AnyFlatSpec: | |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 ) } @@ -146,7 +143,6 @@ class QuerySyntaxTest extends AnyFlatSpec: """ |import cats.effect.IO | - |import ldbc.dsl.Executor |import ldbc.query.builder.Table |import ldbc.query.builder.syntax.io.* | @@ -154,7 +150,7 @@ class QuerySyntaxTest extends AnyFlatSpec: | |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 ) } @@ -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.* | @@ -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] @@ -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.* | @@ -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.* | @@ -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 @@ -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.* | @@ -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 @@ -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.* | @@ -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 diff --git a/module/ldbc-schema/src/main/scala/ldbc/schema/syntax/package.scala b/module/ldbc-schema/src/main/scala/ldbc/schema/syntax/package.scala index 9c116de61..dd80b737c 100644 --- a/module/ldbc-schema/src/main/scala/ldbc/schema/syntax/package.scala +++ b/module/ldbc-schema/src/main/scala/ldbc/schema/syntax/package.scala @@ -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, @@ -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](