-
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.
- Loading branch information
Showing
18 changed files
with
213 additions
and
123 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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,3 @@ | ||
profile = "slick.jdbc.H2Profile$" | ||
driver = "org.h2.Driver" | ||
url = "jdbc:h2:mem:test2;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'classpath:init.sql'" |
2 changes: 1 addition & 1 deletion
2
...s-codegen/src/test/resources/Models.scala → ...en/src/test/resources/entity/Models.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
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
10 changes: 10 additions & 0 deletions
10
slick-additions-codegen/src/test/resources/entity/package.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,10 @@ | ||
import slick.additions.entity.{EntityKey, Lookup} | ||
|
||
import cats.implicits.toInvariantOps | ||
import io.circe.{Codec, Decoder, Encoder} | ||
|
||
|
||
package object entity { | ||
implicit def codecLookup[K : Encoder: Decoder,A]: Codec[Lookup[K, A]] = | ||
Codec.from(Decoder[K], Encoder[K]).imap[Lookup[K, A]](EntityKey[K, A])(_.key) | ||
} |
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,30 @@ | ||
CREATE TABLE IF NOT EXISTS "colors" ( | ||
"id" BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, | ||
"name" VARCHAR NOT NULL | ||
); | ||
CREATE TABLE IF NOT EXISTS "people" ( | ||
"id" BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, | ||
"first" VARCHAR NOT NULL, | ||
"last" VARCHAR NOT NULL, | ||
"city" VARCHAR NOT NULL DEFAULT 'New York', | ||
"date_joined" DATE NOT NULL DEFAULT now(), | ||
"balance" NUMERIC NOT NULL DEFAULT 0.0, | ||
"best_friend" BIGINT NULL REFERENCES "people"("id") ON DELETE SET NULL, | ||
"col8" FLOAT8 NULL, | ||
"col9" BOOL NULL, | ||
"col10" INT NULL, | ||
"col11" INT NULL, | ||
"col12" INT NULL, | ||
"col13" INT NULL, | ||
"col14" INT NULL, | ||
"col15" INT NULL, | ||
"col16" INT NULL, | ||
"col17" INT NULL, | ||
"col18" INT NULL, | ||
"col19" INT NULL, | ||
"col20" INT NULL, | ||
"col21" INT NULL, | ||
"col22" INT NULL, | ||
"col23" INT NULL, | ||
"col24" INT NULL | ||
); |
28 changes: 28 additions & 0 deletions
28
slick-additions-codegen/src/test/resources/plain/Models.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,28 @@ | ||
package plain | ||
case class ColorsRow(id: Long, name: String) | ||
case class PeopleRow( | ||
id: Long, | ||
first: String, | ||
last: String, | ||
city: String = "New York", | ||
dateJoined: java.time.LocalDate = java.time.LocalDate.now(), | ||
balance: BigDecimal = BigDecimal("0.0"), | ||
bestFriend: Option[Long] = None, | ||
col8: Option[Double] = None, | ||
col9: Option[Boolean] = None, | ||
col10: Option[Int] = None, | ||
col11: Option[Int] = None, | ||
col12: Option[Int] = None, | ||
col13: Option[Int] = None, | ||
col14: Option[Int] = None, | ||
col15: Option[Int] = None, | ||
col16: Option[Int] = None, | ||
col17: Option[Int] = None, | ||
col18: Option[Int] = None, | ||
col19: Option[Int] = None, | ||
col20: Option[Int] = None, | ||
col21: Option[Int] = None, | ||
col22: Option[Int] = None, | ||
col23: Option[Int] = None, | ||
col24: Option[Int] = None | ||
) |
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
9 changes: 9 additions & 0 deletions
9
slick-additions-codegen/src/test/scala/slick/additions/codegen/CodeGen.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,9 @@ | ||
package slick.additions.codegen | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.global | ||
|
||
|
||
object CodeGen extends App { | ||
for (codeGeneration <- CodeGeneration.all) | ||
Util.writeToFile(codeGeneration) | ||
} |
14 changes: 14 additions & 0 deletions
14
slick-additions-codegen/src/test/scala/slick/additions/codegen/CodeGenTests.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,14 @@ | ||
package slick.additions.codegen | ||
|
||
import scala.io.Source | ||
|
||
import org.scalatest.funsuite.AsyncFunSuite | ||
|
||
|
||
class CodeGenTests extends AsyncFunSuite { | ||
for (codeGeneration <- CodeGeneration.all) | ||
test(codeGeneration.filename) { | ||
Util.codeString(codeGeneration) | ||
.map(assertResult(Source.fromResource(codeGeneration.filename).mkString)(_)) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
slick-additions-codegen/src/test/scala/slick/additions/codegen/CodeGeneration.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,26 @@ | ||
package slick.additions.codegen | ||
|
||
import slick.additions.codegen.extra.circe.CirceJsonCodecModelsCodeGenerator | ||
import slick.additions.codegen.extra.monocle.MonocleLensesModelsCodeGenerator | ||
|
||
|
||
case class CodeGeneration(generator: BaseCodeGenerator, rules: GenerationRules) { | ||
def pkgName = rules.packageName | ||
val filename: String = s"${pkgName}/${rules.container}.scala" | ||
} | ||
object CodeGeneration { | ||
class TestGenerationRules(override val container: String, override val packageName: String) | ||
extends GenerationRules | ||
val all = Seq( | ||
CodeGeneration(new TablesCodeGenerator, new TestGenerationRules("Tables", "plain")), | ||
CodeGeneration(new ModelsCodeGenerator, new TestGenerationRules("Models", "plain")), | ||
CodeGeneration( | ||
new EntityTableModulesCodeGenerator, | ||
new TestGenerationRules("TableModules", "entity") with EntityGenerationRules | ||
), | ||
CodeGeneration( | ||
new KeylessModelsCodeGenerator with MonocleLensesModelsCodeGenerator with CirceJsonCodecModelsCodeGenerator, | ||
new TestGenerationRules("Models", "entity") with EntityGenerationRules | ||
) | ||
) | ||
} |
Oops, something went wrong.