Permalink
Browse files

Fixes #1771. Adds multi-word type support in SQLite codegen.

  • Loading branch information...
Denys Zadorozhnyi
Denys Zadorozhnyi committed Dec 20, 2017
1 parent b2db9e3 commit 4a9561bd81b326dadd0b17d2feb2b259f2cb7ae9
@@ -2,3 +2,4 @@ CREATE TABLE "SUPPLIERS" ("SUP_ID" INTEGER NOT NULL,"SUP_NAME" VARCHAR(254) NOT
CREATE TABLE "COFFEES" ("COF_NAME" VARCHAR(254) NOT NULL,"SUP_ID" INTEGER NOT NULL,"PRICE" DOUBLE NOT NULL,"SALES" INTEGER NOT NULL,"TOTAL" INTEGER NOT NULL,constraint "SUP_FK" foreign key("SUP_ID") references "SUPPLIERS"("SUP_ID") on update NO ACTION on delete NO ACTION);
CREATE TABLE models (modelKey PRIMARY KEY, devKey, name, lang, version, code);
CREATE TABLE "TIMESTAMPS"("TS" TIMESTAMP NOT NULL DEFAULT "2016-07-29 09:14:56" , "TS2" TIMESTAMP NOT NULL DEFAULT "2016-01-01" , "TS3" TIMESTAMP NOT NULL DEFAULT 817466400000, "TS4" TIMESTAMP NOT NULL DEFAULT "21:00:00" , "TS5" TIMESTAMP NOT NULL DEFAULT "2013-10-07T08:23:19.120Z", TS6 TIMESTAMP NOT NULL DEFAULT "now", TS7 TIMESTAMP NOT NULL DEFAULT "2013-10-07 04:23:19.120-04:00");
CREATE TABLE "MULTIWORD_TYPES" ("SMALLINT_UNSIGNED" SMALLINT UNSIGNED NOT NULL, "UNSIGNED_SMALLINT" UNSIGNED SMALLINT NOT NULL, "UNSIGNED_BIG_INT" UNSIGNED BIG INT, "VAR_CHAR_20" VARYING CHARACTER(20));
@@ -85,10 +85,16 @@ object GeneratedCodeTest {
import profile.api._
val s = Supplier(49, "Superior Coffee", "1 Party Place", "Mendocino", "CA", "95460")
val m = Model(Some("key"), Some("1000"), Some("model"), Some("en"), Some("0.0.1"), None)
val mw = MultiwordType(0, 0, Some(0), Some("varchar"))
assertEquals("Int'" , MultiwordTypes.baseTableRow.smallintUnsigned.toNode.nodeType.toString)
assertEquals("Int'" , MultiwordTypes.baseTableRow.unsignedSmallint.toNode.nodeType.toString)
assertEquals("Option[Int']" , MultiwordTypes.baseTableRow.unsignedBigInt.toNode.nodeType.toString)
assertEquals("Option[String']" , MultiwordTypes.baseTableRow.varChar20.toNode.nodeType.toString)
DBIO.seq(
schema.create,
Suppliers += s,
Models += m,
MultiwordTypes += mw,
Timestamps += new Timestamp(),
Timestamps.result.head.map{r =>
val c = new Timestamp()
@@ -98,7 +104,8 @@ object GeneratedCodeTest {
}
},
Suppliers.result.map(assertEquals(List(s), _)),
Models.result.map(assertEquals(List(m), _))
Models.result.map(assertEquals(List(m), _)),
MultiwordTypes.result.map(assertEquals(List(mw), _))
)
}

@@ -93,7 +93,7 @@ trait SQLiteProfile extends JdbcProfile {
class ModelBuilder(mTables: Seq[MTable], ignoreInvalidDefaults: Boolean)(implicit ec: ExecutionContext) extends JdbcModelBuilder(mTables, ignoreInvalidDefaults) {
override def createColumnBuilder(tableBuilder: TableBuilder, meta: MColumn): ColumnBuilder = new ColumnBuilder(tableBuilder, meta) {
/** Regex matcher to extract name and length out of a db type name with length ascription */
final val TypePattern = "^([A-Z]+)(\\(([0-9]+)\\))?$".r
final val TypePattern = "^([A-Z\\s]+)(\\(([0-9]+)\\))?$".r
private val (_dbType,_size) = meta.typeName match {
case TypePattern(d,_,s) => (d, Option(s).map(_.toInt))
case "" => ("TEXT", None)

0 comments on commit 4a9561b

Please sign in to comment.