Skip to content

Commit

Permalink
Merge pull request #9 from innFactory/feat/JavaTime
Browse files Browse the repository at this point in the history
feat: removing joda date support
  • Loading branch information
MoeQuadrat authored Jul 23, 2024
2 parents 789042b + e178d04 commit 5ce6b0e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 75 deletions.
22 changes: 9 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt._
//settings

name := """scala-utils"""
val releaseVersion = "2.0.11"
val releaseVersion = "2.0.12"

val token = sys.env.getOrElse("GITHUB_TOKEN", "")

Expand Down Expand Up @@ -44,7 +44,6 @@ lazy val utilGraphQL = (project in file("util-graphql"))
libraryDependencies ++= Seq(
typesafePlay,
playJson,
joda,
sangria,
sangriaMarshallingApi,
sangriaSlowlog
Expand All @@ -56,16 +55,14 @@ lazy val utilImplicits = (project in file("util-implicits")).settings(
) settings (
name := "util-implicits"
)
val slickPgJts = "com.github.tminglei" %% "slick-pg_jts" % "0.19.3"
val slick = "com.typesafe.slick" %% "slick" % "3.3.3"
val slickCodegen = "com.typesafe.slick" %% "slick-codegen" % "3.3.3"
val slickHikaricp = "com.typesafe.slick" %% "slick-hikaricp" % "3.3.3"
val hikariCP = "com.zaxxer" % "HikariCP" % "5.0.1"
val slickPg = "com.github.tminglei" %% "slick-pg" % "0.20.2"
val slickPgPlayJson = "com.github.tminglei" %% "slick-pg_play-json" % "0.20.2"
val slickJodaMapper = "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.2"
val flyWayCore = "org.flywaydb" % "flyway-core" % "8.4.1"
val joda = "joda-time" % "joda-time" % "2.10.13"
val slickPgJts = "com.github.tminglei" %% "slick-pg_jts" % "0.22.2"
val slick = "com.typesafe.slick" %% "slick" % "3.5.1"
val slickCodegen = "com.typesafe.slick" %% "slick-codegen" % "3.5.1"
val slickHikaricp = "com.typesafe.slick" %% "slick-hikaricp" % "3.5.1"
val hikariCP = "com.zaxxer" % "HikariCP" % "5.1.0"
val slickPg = "com.github.tminglei" %% "slick-pg" % "0.22.2"
val slickPgPlayJson = "com.github.tminglei" %% "slick-pg_play-json" % "0.22.2"
val flyWayCore = "org.flywaydb" % "flyway-core" % "8.4.1"

val playVersion = "2.9.0-RC2"
val typesafePlay = "com.typesafe.play" %% "play" % playVersion
Expand Down Expand Up @@ -111,7 +108,6 @@ lazy val play = (project in file("util-play"))
typesafePlay,
slickPg,
slickPgPlayJson,
slickJodaMapper,
slick,
slickCodegen,
slickHikaricp,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import slick.codegen.SourceCodeGenerator
import slick.sql.SqlProfile.ColumnOption

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.{ Await, Future }

/**
* This customizes the Slick code generator.
*/
abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCodeGeneratorConfig: CustomizedCodeGeneratorConfig, config: Config[T]) {
abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](
customizedCodeGeneratorConfig: CustomizedCodeGeneratorConfig,
config: Config[T]
) {
import scala.concurrent.ExecutionContext.Implicits.global

/**
Expand All @@ -26,7 +29,7 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod
* @param typeName
* @return
*/
def rawTypeMatcherBase(typeName: String): Option[String] = {
def rawTypeMatcherBase(typeName: String): Option[String] =
typeName match {
case "hstore" => Option("Map[String, String]")
case "_text" | "text[]" | "_varchar" | "varchar[]" => Option("List[String]")
Expand All @@ -35,54 +38,47 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod
case "_int2" | "int2[]" => Option("List[Short]")
case s: String => rawTypeMatcherExtension(s)
}
}

/**
* RawTypeMatcher for non standard types like geometry
* override for more type matching
* @param typeName
* @return
*/
def rawTypeMatcherExtension(typeName: String): Option[String] = {
def rawTypeMatcherExtension(typeName: String): Option[String] =
typeName match {
case "geometry" => Option("com.vividsolutions.jts.geom.Geometry")
case _ => None
case "geometry" => Option("com.vividsolutions.jts.geom.Geometry")
case _ => None
}
}

/**
* sql raw type mapper to override standard sql types to custom types
* @param typeName
* @return
*/
def sqlTypeMapper(typeName: String, superRawType: String): String = {
def sqlTypeMapper(typeName: String, superRawType: String): String =
typeName match {
case "java.sql.Date" => "org.joda.time.LocalDate"
case "java.sql.Time" => "org.joda.time.LocalTime"
case "java.sql.Timestamp" => "org.joda.time.DateTime"
case "java.sql.Timestamp" => "java.time.LocalDateTime"
case "java.sql.Date" => "java.time.LocalDate"
case _ => superRawType
}
}

val codeGenImports: String = {
val codeGenImports: String =
s"""
import com.github.tototoshi.slick.PostgresJodaSupport._
import org.joda.time.DateTime
import com.vividsolutions.jts.geom.Point
"""
}

val projectDir: String = System.getProperty("user.dir")

def main(args: Array[String]): Unit =
// write the generated results to file
// write the generated results to file
Await.result(
codegen.map(
_.writeToFile(
profile = customizedCodeGeneratorConfig.profile, // Using customized Codegen profile from config
folder= s"$projectDir${customizedCodeGeneratorConfig.folder}" ,
folder = s"$projectDir${customizedCodeGeneratorConfig.folder}",
pkg = customizedCodeGeneratorConfig.pkg,
container= customizedCodeGeneratorConfig.container,
container = customizedCodeGeneratorConfig.container,
fileName = customizedCodeGeneratorConfig.fileName
)
),
Expand All @@ -94,7 +90,8 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod
val db = slickProfile.api.Database.forURL(config.url, driver = config.jdbcDriver)

lazy val codegen: Future[SourceCodeGenerator] = db.run {
config.slickProfile.defaultTables.map(_.filter(t => included contains t.name.name.toUpperCase))
config.slickProfile.defaultTables
.map(_.filter(t => included contains t.name.name.toUpperCase))
.flatMap(
config.slickProfile
.createModelBuilder(_, ignoreInvalidDefaults = false)
Expand All @@ -110,7 +107,7 @@ abstract class CustomizedCodeGeneratorBase[T <: ExPostgresProfile](customizedCod
override def rawType: String =
model.options
.find(_.isInstanceOf[ColumnOption.SqlType])
.flatMap( tpe => rawTypeMatcherBase(tpe.asInstanceOf[ColumnOption.SqlType].typeName))
.flatMap(tpe => rawTypeMatcherBase(tpe.asInstanceOf[ColumnOption.SqlType].typeName))
.getOrElse(sqlTypeMapper(model.tpe, super.rawType))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import play.api.libs.json.{JsValue, Json}
import slick.basic.Capability

trait XPostgresProfile
extends ExPostgresProfile
extends ExPostgresProfile
with PgArraySupport
with PgDate2Support
with PgRangeSupport
Expand All @@ -26,9 +26,9 @@ trait XPostgresProfile
override val api = CodegenAPI

object CodegenAPI
extends API
extends ExtPostgresAPI
with ArrayImplicits
with DateTimeImplicits
with Date2DateTimeImplicitsDuration
with JsonImplicits
with NetImplicits
with LTreeImplicits
Expand All @@ -38,7 +38,7 @@ trait XPostgresProfile
with PlayJsonImplicits
with SearchImplicits
with SearchAssistants {
implicit val strListTypeMapper: DriverJdbcType[List[String]] =
implicit val strListTypeMapper: DriverJdbcType[List[String]] =
new SimpleArrayJdbcType[String]("text").to(_.toList)
implicit val playJsonArrayTypeMapper: DriverJdbcType[List[JsValue]] =
new AdvancedArrayJdbcType[JsValue](
Expand All @@ -50,4 +50,3 @@ trait XPostgresProfile
}

object XPostgresProfile extends XPostgresProfile

Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package de.innfactory.play.slick.enhanced.query

import de.innfactory.play.db.codegen.XPostgresProfile
import de.innfactory.play.slick.enhanced.utils.filteroptions.{BooleanFilterOptions, DoubleFilterOptions, FilterOptions, IntFilterOptions, LongFilterOptions, LongSeqFilterOptions, OptionStringFilterOptions, SeqFilterOptions, StringFilterOptions}
import de.innfactory.play.slick.enhanced.utils.filteroptions.{
BooleanFilterOptions,
DoubleFilterOptions,
FilterOptions,
IntFilterOptions,
LongFilterOptions,
LongSeqFilterOptions,
OptionStringFilterOptions,
SeqFilterOptions,
StringFilterOptions
}
import play.api.Logger
import slick.lifted.StringColumnExtensionMethods

Expand Down Expand Up @@ -51,11 +61,11 @@ object EnhancedQuery {
applyFilterOptions(processedQuery.filterOptDoubleOptions(option), seq.tail)
case option: SeqFilterOptions[I] => applyFilterOptions(processedQuery.filterOptSeqString(option), seq.tail)
case option: LongSeqFilterOptions[I] => applyFilterOptions(processedQuery.filterOptSeqLong(option), seq.tail)
case option: BooleanFilterOptions[I] => applyFilterOptions(processedQuery.filterOptBooleanOptions(option), seq.tail)
case o => {
case option: BooleanFilterOptions[I] =>
applyFilterOptions(processedQuery.filterOptBooleanOptions(option), seq.tail)
case o =>
Logger.apply("EnhancedQuery").logger.error("process filterOptions | unknown Option: " + o)
applyFilterOptions(query, seq.tail)
}
}

def filterOptStringOptions[T <: StringFilterOptions[I]](
Expand Down Expand Up @@ -97,8 +107,8 @@ object EnhancedQuery {
/* Boolean OPTIONS */

def filterOptBooleanOptions[T <: BooleanFilterOptions[I]](
booleanFilterOption: BooleanFilterOptions[I]
): Query[I, F, Seq] = {
booleanFilterOption: BooleanFilterOptions[I]
): Query[I, F, Seq] = {
implicit val selector: I => Rep[Boolean] = booleanFilterOption.selector
query.filterOptBoolean(booleanFilterOption.equalsOption.value)
}
Expand Down Expand Up @@ -196,8 +206,8 @@ object EnhancedQuery {
/* REP[BOOLEAN] OPTIONS */

def filterOptBoolean(
option: Option[Boolean]
)(implicit selector: I => Rep[Boolean]): Query[I, F, Seq] =
option: Option[Boolean]
)(implicit selector: I => Rep[Boolean]): Query[I, F, Seq] =
query.filterOpt(option)((r, v) => selector(r) === v)

/* REP[STRING] OPTIONS */
Expand Down

0 comments on commit 5ce6b0e

Please sign in to comment.