Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/2024 05 remove cora package dependency from sql package #208

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,20 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
lazy val sql = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.module("sql", "JDBC API wrapped project with Effect System")
.dependsOn(core)
.settings(
libraryDependencies += "org.typelevel" %%% "cats-core" % "2.10.0"
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % "2.5.0"
)
)

lazy val queryBuilder = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.module("query-builder", "Project to build type-safe queries")
.settings(libraryDependencies += "org.scalatest" %%% "scalatest" % "3.2.17" % Test)
.dependsOn(sql)
.dependsOn(core, sql)

lazy val dsl = crossProject(JVMPlatform)
.crossType(CrossType.Full)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package ldbc.dsl.schema
import cats.effect.IO

import ldbc.core.model.*
import ldbc.sql.Parameter
import ldbc.dsl.io.*

case class Country(
Expand Down Expand Up @@ -43,6 +44,10 @@ object Country:
override def toString: String = value
object Continent extends EnumDataType[Continent]

given Parameter[IO, Continent] with
override def bind(statement: PreparedStatement[IO], index: Int, value: Continent): IO[Unit] =
statement.setString(index, value.toString)

given ResultSetReader[IO, Continent] =
ResultSetReader.mapping[IO, String, Continent](str => Continent.valueOf(str.replace(" ", "_")))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package ldbc.dsl.schema
import cats.effect.IO

import ldbc.core.model.*
import ldbc.sql.Parameter
import ldbc.dsl.io.*

case class CountryLanguage(
Expand All @@ -24,6 +25,10 @@ object CountryLanguage:
case T, F
object IsOfficial extends EnumDataType[IsOfficial]

given Parameter[IO, IsOfficial] with
override def bind(statement: PreparedStatement[IO], index: Int, value: IsOfficial): IO[Unit] =
statement.setString(index, value.toString)

given ResultSetReader[IO, IsOfficial] =
ResultSetReader.mapping[IO, String, IsOfficial](str => IsOfficial.valueOf(str))

Expand Down
6 changes: 0 additions & 6 deletions module/ldbc-sql/src/main/scala/ldbc/sql/Parameter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import java.time.{ Instant, LocalDate, LocalDateTime, LocalTime, ZoneId, ZonedDa

import scala.compiletime.*

import ldbc.core.model.Enum

/**
* Trait for setting Scala and Java values to PreparedStatement.
*
Expand Down Expand Up @@ -114,10 +112,6 @@ object Parameter:
case Some(value) => parameter.bind(statement, index, value)
case None => nullParameter.bind(statement, index, null)

given [F[_]]: Parameter[F, Enum] with
override def bind(statement: PreparedStatement[F], index: Int, value: Enum): F[Unit] =
statement.setString(index, value.toString)

given [F[_], T](using parameter: Parameter[F, String]): Parameter[F, List[T]] with
override def bind(statement: PreparedStatement[F], index: Int, value: List[T]): F[Unit] =
parameter.bind(statement, index, value.mkString(","))
Expand Down