-
Notifications
You must be signed in to change notification settings - Fork 16
Quill 1.0.1 support with java.time. #11
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ case class CodegenOptions( | |
@HelpMessage("only tested with postgresql") jdbcDriver: String = "org.postgresql.Driver", | ||
@HelpMessage( | ||
"top level imports of generated file" | ||
) imports: String = """import io.getquill.WrappedValue""", | ||
) imports: String = """""", | ||
@HelpMessage( | ||
"package name for generated classes" | ||
) `package`: String = "tables", | ||
|
@@ -140,8 +140,31 @@ case class Codegen(options: CodegenOptions, namingStrategy: NamingStrategy) { | |
s"""|package ${options.`package`} | ||
|${options.imports} | ||
| | ||
|/** | ||
| * Generated using [[https://github.com/olafurpg/scala-db-codegen scala-db-codegen]] | ||
| * - Number of tables: ${tables.size} | ||
| * - Database URL: ${options.url} | ||
| * - Database schema: ${options.schema} | ||
| * - Database user: ${options.user} | ||
| */ | ||
|//noinspection ScalaStyle | ||
|object Tables { | ||
| | ||
| /** | ||
| * Quill used to have this trait before v1, but it's still useful to keep. | ||
| * Examples are: pattern matching on wrapped type and conversion to JSON objects. | ||
| */ | ||
| trait WrappedValue[T] extends Any with WrappedType { self: AnyVal => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A separate file maybe? I think a separate project is a bit overkill for only 7 lines of code. If we generate two files (one dynamic and one static) in the same package, then the generated code is fully stand-alone valid Scala code and users won't need to manually fix imports and such. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a "staticFile: Option[File]" option where we write static contents if the setting is configured. WDYT? |
||
| type Type = T | ||
| def value: T | ||
| override def toString = s"$$value" | ||
| } | ||
| | ||
| trait WrappedType extends Any { | ||
| type Type | ||
| def value: Type | ||
| } | ||
| | ||
|$body | ||
|} | ||
""".stripMargin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ object TypeMap { | |
"varchar" -> "String", | ||
"serial" -> "Int", | ||
"bigserial" -> "Long", | ||
"timestamp" -> "java.util.Date", | ||
"timestamp" -> "java.time.LocalDateTime", // Since Quill 1.0.1, the scalajs-java-time library supports java time. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yay \o/ I haven't tried scalajs-java-time yet, seems to still be a wip. However, I'm happy to change the default since I suspect the scalajs use-case is not important for all quill users. Worst case, it's still still possible to override this in case you want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also don't have any experience with |
||
"bytea" -> "Array[Byte]", // PostgreSQL | ||
"uuid" -> "java.util.UUID", // H2, PostgreSQL | ||
"json" -> "String" // PostgreSQL | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!