-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MonocleLensesModelsCodeGenerator, and move CirceJsonCodecModelsCo…
…deGenerator to `extra` subpackage
- Loading branch information
Showing
4 changed files
with
57 additions
and
19 deletions.
There are no files selected for viewing
19 changes: 0 additions & 19 deletions
19
...ns-codegen/src/main/scala/slick/additions/codegen/CirceJsonCodecModelsCodeGenerator.scala
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...rc/main/scala/slick/additions/codegen/extra/circe/CirceJsonCodecModelsCodeGenerator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package slick.additions.codegen.extra.circe | ||
|
||
import scala.meta.{Init, Mod, Name, Type} | ||
|
||
import slick.additions.codegen.{ | ||
ModelsCodeGenerator, | ||
TableConfig, | ||
scalametaDefnClassExtensionMethods | ||
} | ||
|
||
/** Annotates model classes with Circe's `@JsonCodec`. | ||
* | ||
* Generated code requires `circe-generic` | ||
*/ | ||
trait CirceJsonCodecModelsCodeGenerator extends ModelsCodeGenerator { | ||
override protected def modelClass(tableConfig: TableConfig) = | ||
super | ||
.modelClass(tableConfig) | ||
.withMod(Mod.Annot(Init(Type.Name("JsonCodec"), Name.Anonymous(), Nil))) | ||
|
||
override protected def imports(strings: List[String]) = | ||
super.imports(strings :+ "io.circe.generic.JsonCodec") | ||
} |
29 changes: 29 additions & 0 deletions
29
...c/main/scala/slick/additions/codegen/extra/monocle/MonocleLensesModelsCodeGenerator.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package slick.additions.codegen.extra.monocle | ||
|
||
import scala.meta._ | ||
|
||
import slick.additions.codegen.{ | ||
ModelsCodeGenerator, | ||
TableConfig, | ||
scalametaDefnClassExtensionMethods | ||
} | ||
|
||
/** Annotates model classes with Monocle's `@Lenses`. | ||
* | ||
* Generated code requires `monocle-macro` | ||
*/ | ||
trait MonocleLensesModelsCodeGenerator extends ModelsCodeGenerator { | ||
override protected def modelClass(tableConfig: TableConfig) = | ||
super | ||
.modelClass(tableConfig) | ||
.withMod(Mod.Annot(Init(Type.Name("Lenses"), Name.Anonymous(), Nil))) | ||
|
||
override protected def rowStats(tableConfig: TableConfig) = | ||
List( | ||
modelClass(tableConfig), | ||
q"object ${Term.Name(tableConfig.modelClassName)}" | ||
) | ||
|
||
override protected def imports(strings: List[String]) = | ||
super.imports(strings :+ "monocle.macros.Lenses") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters