From 53539fa8205327828958748dbd00b78e13bf6813 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Mon, 1 Jan 2024 23:08:15 +0100 Subject: [PATCH] Add `Options#enablePrimaryKeyType` (fix #77) (#83) --- .../customize-selected-relations.md | 30 +------------- site-in/customization/overview.md | 1 + site-in/customization/selector.md | 40 +++++++++++++++++++ site-in/type-safety/id-types.md | 19 ++++++++- site/sidebars.js | 1 + .../scripts/GeneratedAdventureWorks.scala | 7 ++-- .../adventureworks/pr/bom/BomViewFields.scala | 5 +-- .../adventureworks/pr/bom/BomViewRow.scala | 17 ++++---- .../pr/bom/BomViewStructure.scala | 5 +-- .../BillofmaterialsFields.scala | 2 +- .../billofmaterials/BillofmaterialsId.scala | 37 ----------------- .../billofmaterials/BillofmaterialsRepo.scala | 6 +-- .../BillofmaterialsRepoImpl.scala | 18 ++++----- .../BillofmaterialsRepoMock.scala | 8 ++-- .../billofmaterials/BillofmaterialsRow.scala | 10 ++--- .../BillofmaterialsRowUnsaved.scala | 10 ++--- .../BillofmaterialsStructure.scala | 2 +- .../adventureworks/testInsert.scala | 3 +- .../adventureworks/pr/bom/BomViewFields.scala | 5 +-- .../adventureworks/pr/bom/BomViewRow.scala | 17 ++++---- .../pr/bom/BomViewStructure.scala | 5 +-- .../BillofmaterialsFields.scala | 2 +- .../billofmaterials/BillofmaterialsId.scala | 33 --------------- .../billofmaterials/BillofmaterialsRepo.scala | 6 +-- .../BillofmaterialsRepoImpl.scala | 18 ++++----- .../BillofmaterialsRepoMock.scala | 8 ++-- .../billofmaterials/BillofmaterialsRow.scala | 12 +++--- .../BillofmaterialsRowUnsaved.scala | 10 ++--- .../BillofmaterialsStructure.scala | 2 +- .../adventureworks/testInsert.scala | 3 +- .../adventureworks/pr/bom/BomViewFields.scala | 5 +-- .../adventureworks/pr/bom/BomViewRow.scala | 17 ++++---- .../pr/bom/BomViewStructure.scala | 5 +-- .../BillofmaterialsFields.scala | 2 +- .../billofmaterials/BillofmaterialsId.scala | 35 ---------------- .../billofmaterials/BillofmaterialsRepo.scala | 6 +-- .../BillofmaterialsRepoImpl.scala | 20 +++++----- .../BillofmaterialsRepoMock.scala | 8 ++-- .../billofmaterials/BillofmaterialsRow.scala | 10 ++--- .../BillofmaterialsRowUnsaved.scala | 10 ++--- .../BillofmaterialsStructure.scala | 2 +- .../adventureworks/testInsert.scala | 3 +- typo/src/scala/typo/Options.scala | 1 + .../scala/typo/internal/ComputedTable.scala | 2 + typo/src/scala/typo/internal/IdComputed.scala | 7 +++- .../scala/typo/internal/InternalOptions.scala | 1 + .../typo/internal/codegen/FilesTable.scala | 4 +- typo/src/scala/typo/internal/generate.scala | 1 + 48 files changed, 202 insertions(+), 279 deletions(-) create mode 100644 site-in/customization/selector.md delete mode 100644 typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala delete mode 100644 typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala delete mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala diff --git a/site-in/customization/customize-selected-relations.md b/site-in/customization/customize-selected-relations.md index 2488755af6..9a1072733d 100644 --- a/site-in/customization/customize-selected-relations.md +++ b/site-in/customization/customize-selected-relations.md @@ -9,6 +9,7 @@ Maybe you're generating code for just a part of the system, not the whole thing. Typo has a mechanism by which you can choose which relations to generate code for. among the arguments to `generateFromDb` is `selector`, which by default picks all relations except those in the postgres schemas. +See [Selector](customization/selector.md) ```scala import typo.* @@ -16,35 +17,6 @@ import typo.* generateFromDb(options, selector = Selector.ExcludePostgresInternal) ``` -## `Selector` - -You can pick relations by expressing with `Selector` what you want: -```scala mdoc:silent -import typo.* - -val personAndPet0 = Selector.fullRelationNames("myschema.person", "myschemapet") // picks exactly these tables -val personAndPet = Selector.relationNames("person", "pet") // picks these regardless of schema -val mySchema = Selector.schemas("myschema") // picks all relations in schema - -// heaviest syntax, but most flexible -val custom: Selector = relName => relName.schema.exists(_.contains("foo")) && relName.name.contains("bar") - -// can also invert the selector -!Selector.schemas("myschema") // matches everything except schema "myschema" -``` - -Selectors are also composable: - -```scala mdoc:silent -// picks relations which are called `person` or `pet` AND are in the `myschema` schema -personAndPet and mySchema - -// picks those who are *both* called `person` or `pet` OR are in the `myschema` schema. -// This will typically select more relations -personAndPet or mySchema -``` - -The and/or names follows boolean logic, and may actually be a bit counter-intuitive in this particular context. Suggestions welcome to improve naming ## Transitive relations diff --git a/site-in/customization/overview.md b/site-in/customization/overview.md index 68f8ce2a6d..8eb500530d 100644 --- a/site-in/customization/overview.md +++ b/site-in/customization/overview.md @@ -32,6 +32,7 @@ val options = Options( | `enableFieldValue` | Controls whether to enable `FieldValue` code generation for specific repositories (default is disabled). | | `enableStreamingInserts` | Controls whether to enable [streaming inserts](other-features/streaming-inserts.md) | | `enableTestInserts` | Controls whether to enable [test inserts](other-features/testing-with-random-values.md) for specific repositories (default is none). | +| `enablePrimaryKeyType` | Controls whether to enable [primary key types](type-safety/id-types.md) for specific repositories (default is all). | | `readonlyRepo` | Specifies whether to generate read-only repositories for specific repositories. Useful when you're working on a part of the system where you only consume certain tables. (default is `false` - all mutable). | | `enableDsl` | Enables the [SQL DSL](what-is/dsl.md) for code generation (default is `false`). | | `keepDependencies` | Specifies whether to generate [table dependencies](type-safety/type-flow.md) in generated code even if you didn't select them (default is `false`). | diff --git a/site-in/customization/selector.md b/site-in/customization/selector.md new file mode 100644 index 0000000000..1d14cf507b --- /dev/null +++ b/site-in/customization/selector.md @@ -0,0 +1,40 @@ +--- +title: Picking subsets of relations with Selector +--- + +For much of the customization, you select sets of relations, or enable particular pieces of code generation for a set of relations. + +In order to make this convenient, there is a `Selector` data type. + +## Pick relations by name or by schema +You can pick relations by expressing with `Selector` what you want: + +```scala mdoc:silent +import typo.* + +val personAndPet0 = Selector.fullRelationNames("myschema.person", "myschemapet") // picks exactly these tables +val personAndPet = Selector.relationNames("person", "pet") // picks these regardless of schema +val mySchema = Selector.schemas("myschema") // picks all relations in schema + +// heaviest syntax, but most flexible +val custom: Selector = relName => relName.schema.exists(_.contains("foo")) && relName.name.contains("bar") + +``` + +### Selectors can be inverted +```scala mdoc:silent +!Selector.schemas("myschema") // matches everything except schema "myschema" +``` + +### Selectors are also composable: + +```scala mdoc:silent +// picks relations which are called `person` or `pet` AND are in the `myschema` schema +personAndPet and mySchema + +// picks those who are *both* called `person` or `pet` OR are in the `myschema` schema. +// This will typically select more relations +personAndPet or mySchema +``` + +The and/or names follows boolean logic, and may actually be a bit counter-intuitive in this particular context. Suggestions welcome to improve naming diff --git a/site-in/type-safety/id-types.md b/site-in/type-safety/id-types.md index af04a1dab6..8eb24904c6 100644 --- a/site-in/type-safety/id-types.md +++ b/site-in/type-safety/id-types.md @@ -31,4 +31,21 @@ case class EmployeedepartmenthistoryId( object EmployeedepartmenthistoryId { // ...instances } -``` \ No newline at end of file +``` + +## I don't want these + +if you have some tables where you don't want the type-safety this brings, you can [customize](customization/overview.md) +code generation by tweaking `Options#enablePrimaryKeyType`: + +```scala mdoc:silent +import typo.* + +val options = Options( + pkg = "mypkg", + Some(DbLibName.Doobie), + enablePrimaryKeyType = Selector.relationNames("myrelationname"), +) +``` + +Composite id key types are currently always created. diff --git a/site/sidebars.js b/site/sidebars.js index 39582079e9..705c5a011b 100644 --- a/site/sidebars.js +++ b/site/sidebars.js @@ -82,6 +82,7 @@ const sidebars = { {type: "doc", id: "customization/customize-naming"}, {type: "doc", id: "customization/customize-nullability"}, {type: "doc", id: "customization/customize-types"}, + {type: "doc", id: "customization/selector"}, ], }, ] diff --git a/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala b/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala index 04797f0136..19911509e8 100644 --- a/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala +++ b/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala @@ -46,10 +46,11 @@ object GeneratedAdventureWorks { case (_, "firstname") => "adventureworks.userdefined.FirstName" case ("sales.creditcard", "creditcardid") => "adventureworks.userdefined.CustomCreditcardId" }, - enableDsl = true, - enableTestInserts = Selector.All, generateMockRepos = !Selector.relationNames("purchaseorderdetail"), - readonlyRepo = Selector.relationNames("purchaseorderdetail") + enablePrimaryKeyType = !Selector.relationNames("billofmaterials"), + enableTestInserts = Selector.All, + readonlyRepo = Selector.relationNames("purchaseorderdetail"), + enableDsl = true ) val targetSources = buildDir.resolve(s"$projectPath/generated-and-checked-in") diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala index 17cc54864e..16f06fd6db 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala @@ -9,15 +9,14 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import typo.dsl.SqlExpr.Field import typo.dsl.SqlExpr.OptField trait BomViewFields[Row] { - val id: Field[BillofmaterialsId, Row] - val billofmaterialsid: Field[BillofmaterialsId, Row] + val id: Field[Int, Row] + val billofmaterialsid: Field[Int, Row] val productassemblyid: OptField[ProductId, Row] val componentid: Field[ProductId, Row] val startdate: Field[TypoLocalDateTime, Row] diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala index b9565c30bf..5d50f9033a 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala @@ -9,7 +9,6 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import anorm.Column @@ -26,9 +25,9 @@ import scala.util.Try case class BomViewRow( /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ - id: BillofmaterialsId, + id: Int, /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ - billofmaterialsid: BillofmaterialsId, + billofmaterialsid: Int, /** Points to [[production.billofmaterials.BillofmaterialsRow.productassemblyid]] */ productassemblyid: Option[ProductId], /** Points to [[production.billofmaterials.BillofmaterialsRow.componentid]] */ @@ -51,8 +50,8 @@ object BomViewRow { implicit lazy val reads: Reads[BomViewRow] = Reads[BomViewRow](json => JsResult.fromTry( Try( BomViewRow( - id = json.\("id").as(BillofmaterialsId.reads), - billofmaterialsid = json.\("billofmaterialsid").as(BillofmaterialsId.reads), + id = json.\("id").as(Reads.IntReads), + billofmaterialsid = json.\("billofmaterialsid").as(Reads.IntReads), productassemblyid = json.\("productassemblyid").toOption.map(_.as(ProductId.reads)), componentid = json.\("componentid").as(ProductId.reads), startdate = json.\("startdate").as(TypoLocalDateTime.reads), @@ -68,8 +67,8 @@ object BomViewRow { def rowParser(idx: Int): RowParser[BomViewRow] = RowParser[BomViewRow] { row => Success( BomViewRow( - id = row(idx + 0)(BillofmaterialsId.column), - billofmaterialsid = row(idx + 1)(BillofmaterialsId.column), + id = row(idx + 0)(Column.columnToInt), + billofmaterialsid = row(idx + 1)(Column.columnToInt), productassemblyid = row(idx + 2)(Column.columnToOption(ProductId.column)), componentid = row(idx + 3)(ProductId.column), startdate = row(idx + 4)(TypoLocalDateTime.column), @@ -83,8 +82,8 @@ object BomViewRow { } implicit lazy val writes: OWrites[BomViewRow] = OWrites[BomViewRow](o => new JsObject(ListMap[String, JsValue]( - "id" -> BillofmaterialsId.writes.writes(o.id), - "billofmaterialsid" -> BillofmaterialsId.writes.writes(o.billofmaterialsid), + "id" -> Writes.IntWrites.writes(o.id), + "billofmaterialsid" -> Writes.IntWrites.writes(o.billofmaterialsid), "productassemblyid" -> Writes.OptionWrites(ProductId.writes).writes(o.productassemblyid), "componentid" -> ProductId.writes.writes(o.componentid), "startdate" -> TypoLocalDateTime.writes.writes(o.startdate), diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala index 2536eb9061..2402b93eab 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala @@ -9,7 +9,6 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import typo.dsl.SqlExpr.Field @@ -21,8 +20,8 @@ class BomViewStructure[Row](val prefix: Option[String], val extract: Row => BomV extends Relation[BomViewFields, BomViewRow, Row] with BomViewFields[Row] { outer => - override val id = new Field[BillofmaterialsId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) - override val billofmaterialsid = new Field[BillofmaterialsId, Row](prefix, "billofmaterialsid", None, None)(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) + override val id = new Field[Int, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val billofmaterialsid = new Field[Int, Row](prefix, "billofmaterialsid", None, None)(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) override val productassemblyid = new OptField[ProductId, Row](prefix, "productassemblyid", None, None)(x => extract(x).productassemblyid, (row, value) => merge(row, extract(row).copy(productassemblyid = value))) override val componentid = new Field[ProductId, Row](prefix, "componentid", None, None)(x => extract(x).componentid, (row, value) => merge(row, extract(row).copy(componentid = value))) override val startdate = new Field[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), None)(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala index d1e5d179dd..5182f7e7aa 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala @@ -16,7 +16,7 @@ import typo.dsl.SqlExpr.IdField import typo.dsl.SqlExpr.OptField trait BillofmaterialsFields[Row] { - val billofmaterialsid: IdField[BillofmaterialsId, Row] + val billofmaterialsid: IdField[Int, Row] val productassemblyid: OptField[ProductId, Row] val componentid: Field[ProductId, Row] val startdate: Field[TypoLocalDateTime, Row] diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala deleted file mode 100644 index de2a6b1605..0000000000 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala +++ /dev/null @@ -1,37 +0,0 @@ -/** - * File has been automatically generated by `typo`. - * - * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. - */ -package adventureworks -package production -package billofmaterials - -import adventureworks.Text -import anorm.Column -import anorm.ParameterMetaData -import anorm.ToStatement -import play.api.libs.json.Reads -import play.api.libs.json.Writes -import typo.dsl.Bijection - -/** Type for the primary key of table `production.billofmaterials` */ -case class BillofmaterialsId(value: Int) extends AnyVal -object BillofmaterialsId { - implicit lazy val arrayColumn: Column[Array[BillofmaterialsId]] = Column.columnToArray(column, implicitly) - implicit lazy val arrayToStatement: ToStatement[Array[BillofmaterialsId]] = adventureworks.IntArrayToStatement.contramap(_.map(_.value)) - implicit lazy val bijection: Bijection[BillofmaterialsId, Int] = Bijection[BillofmaterialsId, Int](_.value)(BillofmaterialsId.apply) - implicit lazy val column: Column[BillofmaterialsId] = Column.columnToInt.map(BillofmaterialsId.apply) - implicit lazy val ordering: Ordering[BillofmaterialsId] = Ordering.by(_.value) - implicit lazy val parameterMetadata: ParameterMetaData[BillofmaterialsId] = new ParameterMetaData[BillofmaterialsId] { - override def sqlType: String = ParameterMetaData.IntParameterMetaData.sqlType - override def jdbcType: Int = ParameterMetaData.IntParameterMetaData.jdbcType - } - implicit lazy val reads: Reads[BillofmaterialsId] = Reads.IntReads.map(BillofmaterialsId.apply) - implicit lazy val text: Text[BillofmaterialsId] = new Text[BillofmaterialsId] { - override def unsafeEncode(v: BillofmaterialsId, sb: StringBuilder) = Text.intInstance.unsafeEncode(v.value, sb) - override def unsafeArrayEncode(v: BillofmaterialsId, sb: StringBuilder) = Text.intInstance.unsafeArrayEncode(v.value, sb) - } - implicit lazy val toStatement: ToStatement[BillofmaterialsId] = ToStatement.intToStatement.contramap(_.value) - implicit lazy val writes: Writes[BillofmaterialsId] = Writes.IntWrites.contramap(_.value) -} diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala index 506dad5302..679e9e0896 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala @@ -13,7 +13,7 @@ import typo.dsl.SelectBuilder import typo.dsl.UpdateBuilder trait BillofmaterialsRepo { - def delete(billofmaterialsid: BillofmaterialsId)(implicit c: Connection): Boolean + def delete(billofmaterialsid: Int)(implicit c: Connection): Boolean def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] def insert(unsaved: BillofmaterialsRow)(implicit c: Connection): BillofmaterialsRow def insertStreaming(unsaved: Iterator[BillofmaterialsRow], batchSize: Int)(implicit c: Connection): Long @@ -22,8 +22,8 @@ trait BillofmaterialsRepo { def insertUnsavedStreaming(unsaved: Iterator[BillofmaterialsRowUnsaved], batchSize: Int)(implicit c: Connection): Long def select: SelectBuilder[BillofmaterialsFields, BillofmaterialsRow] def selectAll(implicit c: Connection): List[BillofmaterialsRow] - def selectById(billofmaterialsid: BillofmaterialsId)(implicit c: Connection): Option[BillofmaterialsRow] - def selectByIds(billofmaterialsids: Array[BillofmaterialsId])(implicit c: Connection): List[BillofmaterialsRow] + def selectById(billofmaterialsid: Int)(implicit c: Connection): Option[BillofmaterialsRow] + def selectByIds(billofmaterialsids: Array[Int])(implicit c: Connection): List[BillofmaterialsRow] def update(row: BillofmaterialsRow)(implicit c: Connection): Boolean def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] def upsert(unsaved: BillofmaterialsRow)(implicit c: Connection): BillofmaterialsRow diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala index 06b0541c67..867f963e53 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala @@ -27,15 +27,15 @@ import typo.dsl.SelectBuilderSql import typo.dsl.UpdateBuilder class BillofmaterialsRepoImpl extends BillofmaterialsRepo { - override def delete(billofmaterialsid: BillofmaterialsId)(implicit c: Connection): Boolean = { - SQL"""delete from production.billofmaterials where "billofmaterialsid" = ${ParameterValue(billofmaterialsid, null, BillofmaterialsId.toStatement)}""".executeUpdate() > 0 + override def delete(billofmaterialsid: Int)(implicit c: Connection): Boolean = { + SQL"""delete from production.billofmaterials where "billofmaterialsid" = ${ParameterValue(billofmaterialsid, null, ToStatement.intToStatement)}""".executeUpdate() > 0 } override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { DeleteBuilder("production.billofmaterials", BillofmaterialsFields) } override def insert(unsaved: BillofmaterialsRow)(implicit c: Connection): BillofmaterialsRow = { SQL"""insert into production.billofmaterials("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate") - values (${ParameterValue(unsaved.billofmaterialsid, null, BillofmaterialsId.toStatement)}::int4, ${ParameterValue(unsaved.productassemblyid, null, ToStatement.optionToStatement(ProductId.toStatement, ProductId.parameterMetadata))}::int4, ${ParameterValue(unsaved.componentid, null, ProductId.toStatement)}::int4, ${ParameterValue(unsaved.startdate, null, TypoLocalDateTime.toStatement)}::timestamp, ${ParameterValue(unsaved.enddate, null, ToStatement.optionToStatement(TypoLocalDateTime.toStatement, TypoLocalDateTime.parameterMetadata))}::timestamp, ${ParameterValue(unsaved.unitmeasurecode, null, UnitmeasureId.toStatement)}::bpchar, ${ParameterValue(unsaved.bomlevel, null, TypoShort.toStatement)}::int2, ${ParameterValue(unsaved.perassemblyqty, null, ToStatement.scalaBigDecimalToStatement)}::numeric, ${ParameterValue(unsaved.modifieddate, null, TypoLocalDateTime.toStatement)}::timestamp) + values (${ParameterValue(unsaved.billofmaterialsid, null, ToStatement.intToStatement)}::int4, ${ParameterValue(unsaved.productassemblyid, null, ToStatement.optionToStatement(ProductId.toStatement, ProductId.parameterMetadata))}::int4, ${ParameterValue(unsaved.componentid, null, ProductId.toStatement)}::int4, ${ParameterValue(unsaved.startdate, null, TypoLocalDateTime.toStatement)}::timestamp, ${ParameterValue(unsaved.enddate, null, ToStatement.optionToStatement(TypoLocalDateTime.toStatement, TypoLocalDateTime.parameterMetadata))}::timestamp, ${ParameterValue(unsaved.unitmeasurecode, null, UnitmeasureId.toStatement)}::bpchar, ${ParameterValue(unsaved.bomlevel, null, TypoShort.toStatement)}::int2, ${ParameterValue(unsaved.perassemblyqty, null, ToStatement.scalaBigDecimalToStatement)}::numeric, ${ParameterValue(unsaved.modifieddate, null, TypoLocalDateTime.toStatement)}::timestamp) returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text """ .executeInsert(BillofmaterialsRow.rowParser(1).single) @@ -53,7 +53,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { Some((NamedParameter("bomlevel", ParameterValue(unsaved.bomlevel, null, TypoShort.toStatement)), "::int2")), unsaved.billofmaterialsid match { case Defaulted.UseDefault => None - case Defaulted.Provided(value) => Some((NamedParameter("billofmaterialsid", ParameterValue(value, null, BillofmaterialsId.toStatement)), "::int4")) + case Defaulted.Provided(value) => Some((NamedParameter("billofmaterialsid", ParameterValue(value, null, ToStatement.intToStatement)), "::int4")) }, unsaved.startdate match { case Defaulted.UseDefault => None @@ -96,13 +96,13 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { from production.billofmaterials """.as(BillofmaterialsRow.rowParser(1).*) } - override def selectById(billofmaterialsid: BillofmaterialsId)(implicit c: Connection): Option[BillofmaterialsRow] = { + override def selectById(billofmaterialsid: Int)(implicit c: Connection): Option[BillofmaterialsRow] = { SQL"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials - where "billofmaterialsid" = ${ParameterValue(billofmaterialsid, null, BillofmaterialsId.toStatement)} + where "billofmaterialsid" = ${ParameterValue(billofmaterialsid, null, ToStatement.intToStatement)} """.as(BillofmaterialsRow.rowParser(1).singleOpt) } - override def selectByIds(billofmaterialsids: Array[BillofmaterialsId])(implicit c: Connection): List[BillofmaterialsRow] = { + override def selectByIds(billofmaterialsids: Array[Int])(implicit c: Connection): List[BillofmaterialsRow] = { SQL"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ANY(${billofmaterialsids}) @@ -120,7 +120,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { "bomlevel" = ${ParameterValue(row.bomlevel, null, TypoShort.toStatement)}::int2, "perassemblyqty" = ${ParameterValue(row.perassemblyqty, null, ToStatement.scalaBigDecimalToStatement)}::numeric, "modifieddate" = ${ParameterValue(row.modifieddate, null, TypoLocalDateTime.toStatement)}::timestamp - where "billofmaterialsid" = ${ParameterValue(billofmaterialsid, null, BillofmaterialsId.toStatement)} + where "billofmaterialsid" = ${ParameterValue(billofmaterialsid, null, ToStatement.intToStatement)} """.executeUpdate() > 0 } override def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] = { @@ -129,7 +129,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { override def upsert(unsaved: BillofmaterialsRow)(implicit c: Connection): BillofmaterialsRow = { SQL"""insert into production.billofmaterials("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate") values ( - ${ParameterValue(unsaved.billofmaterialsid, null, BillofmaterialsId.toStatement)}::int4, + ${ParameterValue(unsaved.billofmaterialsid, null, ToStatement.intToStatement)}::int4, ${ParameterValue(unsaved.productassemblyid, null, ToStatement.optionToStatement(ProductId.toStatement, ProductId.parameterMetadata))}::int4, ${ParameterValue(unsaved.componentid, null, ProductId.toStatement)}::int4, ${ParameterValue(unsaved.startdate, null, TypoLocalDateTime.toStatement)}::timestamp, diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala index 962a1a3dd2..af73f45483 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala @@ -20,8 +20,8 @@ import typo.dsl.UpdateBuilder.UpdateBuilderMock import typo.dsl.UpdateParams class BillofmaterialsRepoMock(toRow: Function1[BillofmaterialsRowUnsaved, BillofmaterialsRow], - map: scala.collection.mutable.Map[BillofmaterialsId, BillofmaterialsRow] = scala.collection.mutable.Map.empty) extends BillofmaterialsRepo { - override def delete(billofmaterialsid: BillofmaterialsId)(implicit c: Connection): Boolean = { + map: scala.collection.mutable.Map[Int, BillofmaterialsRow] = scala.collection.mutable.Map.empty) extends BillofmaterialsRepo { + override def delete(billofmaterialsid: Int)(implicit c: Connection): Boolean = { map.remove(billofmaterialsid).isDefined } override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { @@ -58,10 +58,10 @@ class BillofmaterialsRepoMock(toRow: Function1[BillofmaterialsRowUnsaved, Billof override def selectAll(implicit c: Connection): List[BillofmaterialsRow] = { map.values.toList } - override def selectById(billofmaterialsid: BillofmaterialsId)(implicit c: Connection): Option[BillofmaterialsRow] = { + override def selectById(billofmaterialsid: Int)(implicit c: Connection): Option[BillofmaterialsRow] = { map.get(billofmaterialsid) } - override def selectByIds(billofmaterialsids: Array[BillofmaterialsId])(implicit c: Connection): List[BillofmaterialsRow] = { + override def selectByIds(billofmaterialsids: Array[Int])(implicit c: Connection): List[BillofmaterialsRow] = { billofmaterialsids.flatMap(map.get).toList } override def update(row: BillofmaterialsRow)(implicit c: Connection): Boolean = { diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala index 1956b22a0e..b995710372 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala @@ -27,7 +27,7 @@ import scala.util.Try case class BillofmaterialsRow( /** Primary key for BillOfMaterials records. Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) */ - billofmaterialsid: BillofmaterialsId, + billofmaterialsid: Int, /** Parent product identification number. Foreign key to Product.ProductID. Points to [[product.ProductRow.productid]] Constraint CK_BillOfMaterials_BOMLevel affecting columns bomlevel, perassemblyqty, productassemblyid: ((((productassemblyid IS NULL) AND (bomlevel = 0) AND (perassemblyqty = 1.00)) OR ((productassemblyid IS NOT NULL) AND (bomlevel >= 1)))) @@ -63,7 +63,7 @@ object BillofmaterialsRow { implicit lazy val reads: Reads[BillofmaterialsRow] = Reads[BillofmaterialsRow](json => JsResult.fromTry( Try( BillofmaterialsRow( - billofmaterialsid = json.\("billofmaterialsid").as(BillofmaterialsId.reads), + billofmaterialsid = json.\("billofmaterialsid").as(Reads.IntReads), productassemblyid = json.\("productassemblyid").toOption.map(_.as(ProductId.reads)), componentid = json.\("componentid").as(ProductId.reads), startdate = json.\("startdate").as(TypoLocalDateTime.reads), @@ -79,7 +79,7 @@ object BillofmaterialsRow { def rowParser(idx: Int): RowParser[BillofmaterialsRow] = RowParser[BillofmaterialsRow] { row => Success( BillofmaterialsRow( - billofmaterialsid = row(idx + 0)(BillofmaterialsId.column), + billofmaterialsid = row(idx + 0)(Column.columnToInt), productassemblyid = row(idx + 1)(Column.columnToOption(ProductId.column)), componentid = row(idx + 2)(ProductId.column), startdate = row(idx + 3)(TypoLocalDateTime.column), @@ -92,7 +92,7 @@ object BillofmaterialsRow { ) } implicit lazy val text: Text[BillofmaterialsRow] = Text.instance[BillofmaterialsRow]{ (row, sb) => - BillofmaterialsId.text.unsafeEncode(row.billofmaterialsid, sb) + Text.intInstance.unsafeEncode(row.billofmaterialsid, sb) sb.append(Text.DELIMETER) Text.option(ProductId.text).unsafeEncode(row.productassemblyid, sb) sb.append(Text.DELIMETER) @@ -112,7 +112,7 @@ object BillofmaterialsRow { } implicit lazy val writes: OWrites[BillofmaterialsRow] = OWrites[BillofmaterialsRow](o => new JsObject(ListMap[String, JsValue]( - "billofmaterialsid" -> BillofmaterialsId.writes.writes(o.billofmaterialsid), + "billofmaterialsid" -> Writes.IntWrites.writes(o.billofmaterialsid), "productassemblyid" -> Writes.OptionWrites(ProductId.writes).writes(o.productassemblyid), "componentid" -> ProductId.writes.writes(o.componentid), "startdate" -> TypoLocalDateTime.writes.writes(o.startdate), diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala index 2821aa7ca1..8ed7eff95d 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala @@ -44,7 +44,7 @@ case class BillofmaterialsRowUnsaved( bomlevel: TypoShort, /** Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) Primary key for BillOfMaterials records. */ - billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + billofmaterialsid: Defaulted[Int] = Defaulted.UseDefault, /** Default: now() Date the component started being used in the assembly item. Constraint CK_BillOfMaterials_EndDate affecting columns e, n, d, d, a, t, e, ,, , s, t, a, r, t, d, a, t, e: (((enddate > startdate) OR (enddate IS NULL))) */ @@ -57,7 +57,7 @@ case class BillofmaterialsRowUnsaved( /** Default: now() */ modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault ) { - def toRow(billofmaterialsidDefault: => BillofmaterialsId, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = + def toRow(billofmaterialsidDefault: => Int, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = BillofmaterialsRow( productassemblyid = productassemblyid, componentid = componentid, @@ -91,7 +91,7 @@ object BillofmaterialsRowUnsaved { enddate = json.\("enddate").toOption.map(_.as(TypoLocalDateTime.reads)), unitmeasurecode = json.\("unitmeasurecode").as(UnitmeasureId.reads), bomlevel = json.\("bomlevel").as(TypoShort.reads), - billofmaterialsid = json.\("billofmaterialsid").as(Defaulted.reads(BillofmaterialsId.reads)), + billofmaterialsid = json.\("billofmaterialsid").as(Defaulted.reads(Reads.IntReads)), startdate = json.\("startdate").as(Defaulted.reads(TypoLocalDateTime.reads)), perassemblyqty = json.\("perassemblyqty").as(Defaulted.reads(Reads.bigDecReads)), modifieddate = json.\("modifieddate").as(Defaulted.reads(TypoLocalDateTime.reads)) @@ -110,7 +110,7 @@ object BillofmaterialsRowUnsaved { sb.append(Text.DELIMETER) TypoShort.text.unsafeEncode(row.bomlevel, sb) sb.append(Text.DELIMETER) - Defaulted.text(BillofmaterialsId.text).unsafeEncode(row.billofmaterialsid, sb) + Defaulted.text(Text.intInstance).unsafeEncode(row.billofmaterialsid, sb) sb.append(Text.DELIMETER) Defaulted.text(TypoLocalDateTime.text).unsafeEncode(row.startdate, sb) sb.append(Text.DELIMETER) @@ -125,7 +125,7 @@ object BillofmaterialsRowUnsaved { "enddate" -> Writes.OptionWrites(TypoLocalDateTime.writes).writes(o.enddate), "unitmeasurecode" -> UnitmeasureId.writes.writes(o.unitmeasurecode), "bomlevel" -> TypoShort.writes.writes(o.bomlevel), - "billofmaterialsid" -> Defaulted.writes(BillofmaterialsId.writes).writes(o.billofmaterialsid), + "billofmaterialsid" -> Defaulted.writes(Writes.IntWrites).writes(o.billofmaterialsid), "startdate" -> Defaulted.writes(TypoLocalDateTime.writes).writes(o.startdate), "perassemblyqty" -> Defaulted.writes(Writes.BigDecimalWrites).writes(o.perassemblyqty), "modifieddate" -> Defaulted.writes(TypoLocalDateTime.writes).writes(o.modifieddate) diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala index 48a762775b..60079addb8 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala @@ -21,7 +21,7 @@ class BillofmaterialsStructure[Row](val prefix: Option[String], val extract: Row extends Relation[BillofmaterialsFields, BillofmaterialsRow, Row] with BillofmaterialsFields[Row] { outer => - override val billofmaterialsid = new IdField[BillofmaterialsId, Row](prefix, "billofmaterialsid", None, Some("int4"))(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) + override val billofmaterialsid = new IdField[Int, Row](prefix, "billofmaterialsid", None, Some("int4"))(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) override val productassemblyid = new OptField[ProductId, Row](prefix, "productassemblyid", None, Some("int4"))(x => extract(x).productassemblyid, (row, value) => merge(row, extract(row).copy(productassemblyid = value))) override val componentid = new Field[ProductId, Row](prefix, "componentid", None, Some("int4"))(x => extract(x).componentid, (row, value) => merge(row, extract(row).copy(componentid = value))) override val startdate = new Field[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), Some("timestamp"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) diff --git a/typo-tester-anorm/generated-and-checked-in/adventureworks/testInsert.scala b/typo-tester-anorm/generated-and-checked-in/adventureworks/testInsert.scala index 8354b3162a..678ad312f8 100644 --- a/typo-tester-anorm/generated-and-checked-in/adventureworks/testInsert.scala +++ b/typo-tester-anorm/generated-and-checked-in/adventureworks/testInsert.scala @@ -98,7 +98,6 @@ import adventureworks.person.stateprovince.StateprovinceId import adventureworks.person.stateprovince.StateprovinceRepoImpl import adventureworks.person.stateprovince.StateprovinceRow import adventureworks.person.stateprovince.StateprovinceRowUnsaved -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.billofmaterials.BillofmaterialsRepoImpl import adventureworks.production.billofmaterials.BillofmaterialsRow import adventureworks.production.billofmaterials.BillofmaterialsRowUnsaved @@ -434,7 +433,7 @@ class TestInsert(random: Random) { productassemblyid: Option[ProductId] = None, enddate: Option[TypoLocalDateTime] = if (random.nextBoolean()) None else Some(TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)))), bomlevel: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), - billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + billofmaterialsid: Defaulted[Int] = Defaulted.UseDefault, startdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, perassemblyqty: Defaulted[BigDecimal] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala index 17cc54864e..16f06fd6db 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala @@ -9,15 +9,14 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import typo.dsl.SqlExpr.Field import typo.dsl.SqlExpr.OptField trait BomViewFields[Row] { - val id: Field[BillofmaterialsId, Row] - val billofmaterialsid: Field[BillofmaterialsId, Row] + val id: Field[Int, Row] + val billofmaterialsid: Field[Int, Row] val productassemblyid: OptField[ProductId, Row] val componentid: Field[ProductId, Row] val startdate: Field[TypoLocalDateTime, Row] diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala index aa1c6049f1..df8711629a 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala @@ -9,7 +9,6 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import doobie.enumerated.Nullability @@ -21,9 +20,9 @@ import java.sql.ResultSet case class BomViewRow( /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ - id: BillofmaterialsId, + id: Int, /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ - billofmaterialsid: BillofmaterialsId, + billofmaterialsid: Int, /** Points to [[production.billofmaterials.BillofmaterialsRow.productassemblyid]] */ productassemblyid: Option[ProductId], /** Points to [[production.billofmaterials.BillofmaterialsRow.componentid]] */ @@ -43,12 +42,12 @@ case class BomViewRow( ) object BomViewRow { - implicit lazy val decoder: Decoder[BomViewRow] = Decoder.forProduct10[BomViewRow, BillofmaterialsId, BillofmaterialsId, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("id", "billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(BomViewRow.apply)(BillofmaterialsId.decoder, BillofmaterialsId.decoder, Decoder.decodeOption(ProductId.decoder), ProductId.decoder, TypoLocalDateTime.decoder, Decoder.decodeOption(TypoLocalDateTime.decoder), UnitmeasureId.decoder, TypoShort.decoder, Decoder.decodeBigDecimal, TypoLocalDateTime.decoder) - implicit lazy val encoder: Encoder[BomViewRow] = Encoder.forProduct10[BomViewRow, BillofmaterialsId, BillofmaterialsId, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("id", "billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(x => (x.id, x.billofmaterialsid, x.productassemblyid, x.componentid, x.startdate, x.enddate, x.unitmeasurecode, x.bomlevel, x.perassemblyqty, x.modifieddate))(BillofmaterialsId.encoder, BillofmaterialsId.encoder, Encoder.encodeOption(ProductId.encoder), ProductId.encoder, TypoLocalDateTime.encoder, Encoder.encodeOption(TypoLocalDateTime.encoder), UnitmeasureId.encoder, TypoShort.encoder, Encoder.encodeBigDecimal, TypoLocalDateTime.encoder) + implicit lazy val decoder: Decoder[BomViewRow] = Decoder.forProduct10[BomViewRow, Int, Int, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("id", "billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(BomViewRow.apply)(Decoder.decodeInt, Decoder.decodeInt, Decoder.decodeOption(ProductId.decoder), ProductId.decoder, TypoLocalDateTime.decoder, Decoder.decodeOption(TypoLocalDateTime.decoder), UnitmeasureId.decoder, TypoShort.decoder, Decoder.decodeBigDecimal, TypoLocalDateTime.decoder) + implicit lazy val encoder: Encoder[BomViewRow] = Encoder.forProduct10[BomViewRow, Int, Int, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("id", "billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(x => (x.id, x.billofmaterialsid, x.productassemblyid, x.componentid, x.startdate, x.enddate, x.unitmeasurecode, x.bomlevel, x.perassemblyqty, x.modifieddate))(Encoder.encodeInt, Encoder.encodeInt, Encoder.encodeOption(ProductId.encoder), ProductId.encoder, TypoLocalDateTime.encoder, Encoder.encodeOption(TypoLocalDateTime.encoder), UnitmeasureId.encoder, TypoShort.encoder, Encoder.encodeBigDecimal, TypoLocalDateTime.encoder) implicit lazy val read: Read[BomViewRow] = new Read[BomViewRow]( gets = List( - (BillofmaterialsId.get, Nullability.NoNulls), - (BillofmaterialsId.get, Nullability.NoNulls), + (Meta.IntMeta.get, Nullability.NoNulls), + (Meta.IntMeta.get, Nullability.NoNulls), (ProductId.get, Nullability.Nullable), (ProductId.get, Nullability.NoNulls), (TypoLocalDateTime.get, Nullability.NoNulls), @@ -59,8 +58,8 @@ object BomViewRow { (TypoLocalDateTime.get, Nullability.NoNulls) ), unsafeGet = (rs: ResultSet, i: Int) => BomViewRow( - id = BillofmaterialsId.get.unsafeGetNonNullable(rs, i + 0), - billofmaterialsid = BillofmaterialsId.get.unsafeGetNonNullable(rs, i + 1), + id = Meta.IntMeta.get.unsafeGetNonNullable(rs, i + 0), + billofmaterialsid = Meta.IntMeta.get.unsafeGetNonNullable(rs, i + 1), productassemblyid = ProductId.get.unsafeGetNullable(rs, i + 2), componentid = ProductId.get.unsafeGetNonNullable(rs, i + 3), startdate = TypoLocalDateTime.get.unsafeGetNonNullable(rs, i + 4), diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala index 2536eb9061..2402b93eab 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala @@ -9,7 +9,6 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import typo.dsl.SqlExpr.Field @@ -21,8 +20,8 @@ class BomViewStructure[Row](val prefix: Option[String], val extract: Row => BomV extends Relation[BomViewFields, BomViewRow, Row] with BomViewFields[Row] { outer => - override val id = new Field[BillofmaterialsId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) - override val billofmaterialsid = new Field[BillofmaterialsId, Row](prefix, "billofmaterialsid", None, None)(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) + override val id = new Field[Int, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val billofmaterialsid = new Field[Int, Row](prefix, "billofmaterialsid", None, None)(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) override val productassemblyid = new OptField[ProductId, Row](prefix, "productassemblyid", None, None)(x => extract(x).productassemblyid, (row, value) => merge(row, extract(row).copy(productassemblyid = value))) override val componentid = new Field[ProductId, Row](prefix, "componentid", None, None)(x => extract(x).componentid, (row, value) => merge(row, extract(row).copy(componentid = value))) override val startdate = new Field[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), None)(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala index d1e5d179dd..5182f7e7aa 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala @@ -16,7 +16,7 @@ import typo.dsl.SqlExpr.IdField import typo.dsl.SqlExpr.OptField trait BillofmaterialsFields[Row] { - val billofmaterialsid: IdField[BillofmaterialsId, Row] + val billofmaterialsid: IdField[Int, Row] val productassemblyid: OptField[ProductId, Row] val componentid: Field[ProductId, Row] val startdate: Field[TypoLocalDateTime, Row] diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala deleted file mode 100644 index b0fbe7ece1..0000000000 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala +++ /dev/null @@ -1,33 +0,0 @@ -/** - * File has been automatically generated by `typo`. - * - * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. - */ -package adventureworks -package production -package billofmaterials - -import doobie.postgres.Text -import doobie.util.Get -import doobie.util.Put -import doobie.util.meta.Meta -import io.circe.Decoder -import io.circe.Encoder -import typo.dsl.Bijection - -/** Type for the primary key of table `production.billofmaterials` */ -case class BillofmaterialsId(value: Int) extends AnyVal -object BillofmaterialsId { - implicit lazy val arrayGet: Get[Array[BillofmaterialsId]] = adventureworks.IntegerArrayMeta.get.map(_.map(BillofmaterialsId.apply)) - implicit lazy val arrayPut: Put[Array[BillofmaterialsId]] = adventureworks.IntegerArrayMeta.put.contramap(_.map(_.value)) - implicit lazy val bijection: Bijection[BillofmaterialsId, Int] = Bijection[BillofmaterialsId, Int](_.value)(BillofmaterialsId.apply) - implicit lazy val decoder: Decoder[BillofmaterialsId] = Decoder.decodeInt.map(BillofmaterialsId.apply) - implicit lazy val encoder: Encoder[BillofmaterialsId] = Encoder.encodeInt.contramap(_.value) - implicit lazy val get: Get[BillofmaterialsId] = Meta.IntMeta.get.map(BillofmaterialsId.apply) - implicit lazy val ordering: Ordering[BillofmaterialsId] = Ordering.by(_.value) - implicit lazy val put: Put[BillofmaterialsId] = Meta.IntMeta.put.contramap(_.value) - implicit lazy val text: Text[BillofmaterialsId] = new Text[BillofmaterialsId] { - override def unsafeEncode(v: BillofmaterialsId, sb: StringBuilder) = Text.intInstance.unsafeEncode(v.value, sb) - override def unsafeArrayEncode(v: BillofmaterialsId, sb: StringBuilder) = Text.intInstance.unsafeArrayEncode(v.value, sb) - } -} diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala index 2c3adcb96c..74b2514355 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala @@ -14,7 +14,7 @@ import typo.dsl.SelectBuilder import typo.dsl.UpdateBuilder trait BillofmaterialsRepo { - def delete(billofmaterialsid: BillofmaterialsId): ConnectionIO[Boolean] + def delete(billofmaterialsid: Int): ConnectionIO[Boolean] def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] def insert(unsaved: BillofmaterialsRow): ConnectionIO[BillofmaterialsRow] def insertStreaming(unsaved: Stream[ConnectionIO, BillofmaterialsRow], batchSize: Int): ConnectionIO[Long] @@ -23,8 +23,8 @@ trait BillofmaterialsRepo { def insertUnsavedStreaming(unsaved: Stream[ConnectionIO, BillofmaterialsRowUnsaved], batchSize: Int): ConnectionIO[Long] def select: SelectBuilder[BillofmaterialsFields, BillofmaterialsRow] def selectAll: Stream[ConnectionIO, BillofmaterialsRow] - def selectById(billofmaterialsid: BillofmaterialsId): ConnectionIO[Option[BillofmaterialsRow]] - def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): Stream[ConnectionIO, BillofmaterialsRow] + def selectById(billofmaterialsid: Int): ConnectionIO[Option[BillofmaterialsRow]] + def selectByIds(billofmaterialsids: Array[Int]): Stream[ConnectionIO, BillofmaterialsRow] def update(row: BillofmaterialsRow): ConnectionIO[Boolean] def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] def upsert(unsaved: BillofmaterialsRow): ConnectionIO[BillofmaterialsRow] diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala index c7c42e585e..5adf1d9980 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala @@ -26,15 +26,15 @@ import typo.dsl.SelectBuilderSql import typo.dsl.UpdateBuilder class BillofmaterialsRepoImpl extends BillofmaterialsRepo { - override def delete(billofmaterialsid: BillofmaterialsId): ConnectionIO[Boolean] = { - sql"""delete from production.billofmaterials where "billofmaterialsid" = ${fromWrite(billofmaterialsid)(Write.fromPut(BillofmaterialsId.put))}""".update.run.map(_ > 0) + override def delete(billofmaterialsid: Int): ConnectionIO[Boolean] = { + sql"""delete from production.billofmaterials where "billofmaterialsid" = ${fromWrite(billofmaterialsid)(Write.fromPut(Meta.IntMeta.put))}""".update.run.map(_ > 0) } override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { DeleteBuilder("production.billofmaterials", BillofmaterialsFields) } override def insert(unsaved: BillofmaterialsRow): ConnectionIO[BillofmaterialsRow] = { sql"""insert into production.billofmaterials("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate") - values (${fromWrite(unsaved.billofmaterialsid)(Write.fromPut(BillofmaterialsId.put))}::int4, ${fromWrite(unsaved.productassemblyid)(Write.fromPutOption(ProductId.put))}::int4, ${fromWrite(unsaved.componentid)(Write.fromPut(ProductId.put))}::int4, ${fromWrite(unsaved.startdate)(Write.fromPut(TypoLocalDateTime.put))}::timestamp, ${fromWrite(unsaved.enddate)(Write.fromPutOption(TypoLocalDateTime.put))}::timestamp, ${fromWrite(unsaved.unitmeasurecode)(Write.fromPut(UnitmeasureId.put))}::bpchar, ${fromWrite(unsaved.bomlevel)(Write.fromPut(TypoShort.put))}::int2, ${fromWrite(unsaved.perassemblyqty)(Write.fromPut(Meta.ScalaBigDecimalMeta.put))}::numeric, ${fromWrite(unsaved.modifieddate)(Write.fromPut(TypoLocalDateTime.put))}::timestamp) + values (${fromWrite(unsaved.billofmaterialsid)(Write.fromPut(Meta.IntMeta.put))}::int4, ${fromWrite(unsaved.productassemblyid)(Write.fromPutOption(ProductId.put))}::int4, ${fromWrite(unsaved.componentid)(Write.fromPut(ProductId.put))}::int4, ${fromWrite(unsaved.startdate)(Write.fromPut(TypoLocalDateTime.put))}::timestamp, ${fromWrite(unsaved.enddate)(Write.fromPutOption(TypoLocalDateTime.put))}::timestamp, ${fromWrite(unsaved.unitmeasurecode)(Write.fromPut(UnitmeasureId.put))}::bpchar, ${fromWrite(unsaved.bomlevel)(Write.fromPut(TypoShort.put))}::int2, ${fromWrite(unsaved.perassemblyqty)(Write.fromPut(Meta.ScalaBigDecimalMeta.put))}::numeric, ${fromWrite(unsaved.modifieddate)(Write.fromPut(TypoLocalDateTime.put))}::timestamp) returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text """.query(BillofmaterialsRow.read).unique } @@ -50,7 +50,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { Some((Fragment.const(s""""bomlevel""""), fr"${fromWrite(unsaved.bomlevel)(Write.fromPut(TypoShort.put))}::int2")), unsaved.billofmaterialsid match { case Defaulted.UseDefault => None - case Defaulted.Provided(value) => Some((Fragment.const(s""""billofmaterialsid""""), fr"${fromWrite(value: BillofmaterialsId)(Write.fromPut(BillofmaterialsId.put))}::int4")) + case Defaulted.Provided(value) => Some((Fragment.const(s""""billofmaterialsid""""), fr"${fromWrite(value: Int)(Write.fromPut(Meta.IntMeta.put))}::int4")) }, unsaved.startdate match { case Defaulted.UseDefault => None @@ -90,10 +90,10 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { override def selectAll: Stream[ConnectionIO, BillofmaterialsRow] = { sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials""".query(BillofmaterialsRow.read).stream } - override def selectById(billofmaterialsid: BillofmaterialsId): ConnectionIO[Option[BillofmaterialsRow]] = { - sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ${fromWrite(billofmaterialsid)(Write.fromPut(BillofmaterialsId.put))}""".query(BillofmaterialsRow.read).option + override def selectById(billofmaterialsid: Int): ConnectionIO[Option[BillofmaterialsRow]] = { + sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ${fromWrite(billofmaterialsid)(Write.fromPut(Meta.IntMeta.put))}""".query(BillofmaterialsRow.read).option } - override def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): Stream[ConnectionIO, BillofmaterialsRow] = { + override def selectByIds(billofmaterialsids: Array[Int]): Stream[ConnectionIO, BillofmaterialsRow] = { sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ANY(${billofmaterialsids})""".query(BillofmaterialsRow.read).stream } override def update(row: BillofmaterialsRow): ConnectionIO[Boolean] = { @@ -107,7 +107,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { "bomlevel" = ${fromWrite(row.bomlevel)(Write.fromPut(TypoShort.put))}::int2, "perassemblyqty" = ${fromWrite(row.perassemblyqty)(Write.fromPut(Meta.ScalaBigDecimalMeta.put))}::numeric, "modifieddate" = ${fromWrite(row.modifieddate)(Write.fromPut(TypoLocalDateTime.put))}::timestamp - where "billofmaterialsid" = ${fromWrite(billofmaterialsid)(Write.fromPut(BillofmaterialsId.put))}""" + where "billofmaterialsid" = ${fromWrite(billofmaterialsid)(Write.fromPut(Meta.IntMeta.put))}""" .update .run .map(_ > 0) @@ -118,7 +118,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { override def upsert(unsaved: BillofmaterialsRow): ConnectionIO[BillofmaterialsRow] = { sql"""insert into production.billofmaterials("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate") values ( - ${fromWrite(unsaved.billofmaterialsid)(Write.fromPut(BillofmaterialsId.put))}::int4, + ${fromWrite(unsaved.billofmaterialsid)(Write.fromPut(Meta.IntMeta.put))}::int4, ${fromWrite(unsaved.productassemblyid)(Write.fromPutOption(ProductId.put))}::int4, ${fromWrite(unsaved.componentid)(Write.fromPut(ProductId.put))}::int4, ${fromWrite(unsaved.startdate)(Write.fromPut(TypoLocalDateTime.put))}::timestamp, diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala index 76d1b249f6..8a73c54faa 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala @@ -22,8 +22,8 @@ import typo.dsl.UpdateBuilder.UpdateBuilderMock import typo.dsl.UpdateParams class BillofmaterialsRepoMock(toRow: Function1[BillofmaterialsRowUnsaved, BillofmaterialsRow], - map: scala.collection.mutable.Map[BillofmaterialsId, BillofmaterialsRow] = scala.collection.mutable.Map.empty) extends BillofmaterialsRepo { - override def delete(billofmaterialsid: BillofmaterialsId): ConnectionIO[Boolean] = { + map: scala.collection.mutable.Map[Int, BillofmaterialsRow] = scala.collection.mutable.Map.empty) extends BillofmaterialsRepo { + override def delete(billofmaterialsid: Int): ConnectionIO[Boolean] = { delay(map.remove(billofmaterialsid).isDefined) } override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { @@ -70,10 +70,10 @@ class BillofmaterialsRepoMock(toRow: Function1[BillofmaterialsRowUnsaved, Billof override def selectAll: Stream[ConnectionIO, BillofmaterialsRow] = { Stream.emits(map.values.toList) } - override def selectById(billofmaterialsid: BillofmaterialsId): ConnectionIO[Option[BillofmaterialsRow]] = { + override def selectById(billofmaterialsid: Int): ConnectionIO[Option[BillofmaterialsRow]] = { delay(map.get(billofmaterialsid)) } - override def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): Stream[ConnectionIO, BillofmaterialsRow] = { + override def selectByIds(billofmaterialsids: Array[Int]): Stream[ConnectionIO, BillofmaterialsRow] = { Stream.emits(billofmaterialsids.flatMap(map.get).toList) } override def update(row: BillofmaterialsRow): ConnectionIO[Boolean] = { diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala index d794030e5d..e44f57f612 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala @@ -22,7 +22,7 @@ import java.sql.ResultSet case class BillofmaterialsRow( /** Primary key for BillOfMaterials records. Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) */ - billofmaterialsid: BillofmaterialsId, + billofmaterialsid: Int, /** Parent product identification number. Foreign key to Product.ProductID. Points to [[product.ProductRow.productid]] Constraint CK_BillOfMaterials_BOMLevel affecting columns bomlevel, perassemblyqty, productassemblyid: ((((productassemblyid IS NULL) AND (bomlevel = 0) AND (perassemblyqty = 1.00)) OR ((productassemblyid IS NOT NULL) AND (bomlevel >= 1)))) @@ -55,11 +55,11 @@ case class BillofmaterialsRow( ) object BillofmaterialsRow { - implicit lazy val decoder: Decoder[BillofmaterialsRow] = Decoder.forProduct9[BillofmaterialsRow, BillofmaterialsId, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(BillofmaterialsRow.apply)(BillofmaterialsId.decoder, Decoder.decodeOption(ProductId.decoder), ProductId.decoder, TypoLocalDateTime.decoder, Decoder.decodeOption(TypoLocalDateTime.decoder), UnitmeasureId.decoder, TypoShort.decoder, Decoder.decodeBigDecimal, TypoLocalDateTime.decoder) - implicit lazy val encoder: Encoder[BillofmaterialsRow] = Encoder.forProduct9[BillofmaterialsRow, BillofmaterialsId, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(x => (x.billofmaterialsid, x.productassemblyid, x.componentid, x.startdate, x.enddate, x.unitmeasurecode, x.bomlevel, x.perassemblyqty, x.modifieddate))(BillofmaterialsId.encoder, Encoder.encodeOption(ProductId.encoder), ProductId.encoder, TypoLocalDateTime.encoder, Encoder.encodeOption(TypoLocalDateTime.encoder), UnitmeasureId.encoder, TypoShort.encoder, Encoder.encodeBigDecimal, TypoLocalDateTime.encoder) + implicit lazy val decoder: Decoder[BillofmaterialsRow] = Decoder.forProduct9[BillofmaterialsRow, Int, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(BillofmaterialsRow.apply)(Decoder.decodeInt, Decoder.decodeOption(ProductId.decoder), ProductId.decoder, TypoLocalDateTime.decoder, Decoder.decodeOption(TypoLocalDateTime.decoder), UnitmeasureId.decoder, TypoShort.decoder, Decoder.decodeBigDecimal, TypoLocalDateTime.decoder) + implicit lazy val encoder: Encoder[BillofmaterialsRow] = Encoder.forProduct9[BillofmaterialsRow, Int, Option[ProductId], ProductId, TypoLocalDateTime, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, BigDecimal, TypoLocalDateTime]("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate")(x => (x.billofmaterialsid, x.productassemblyid, x.componentid, x.startdate, x.enddate, x.unitmeasurecode, x.bomlevel, x.perassemblyqty, x.modifieddate))(Encoder.encodeInt, Encoder.encodeOption(ProductId.encoder), ProductId.encoder, TypoLocalDateTime.encoder, Encoder.encodeOption(TypoLocalDateTime.encoder), UnitmeasureId.encoder, TypoShort.encoder, Encoder.encodeBigDecimal, TypoLocalDateTime.encoder) implicit lazy val read: Read[BillofmaterialsRow] = new Read[BillofmaterialsRow]( gets = List( - (BillofmaterialsId.get, Nullability.NoNulls), + (Meta.IntMeta.get, Nullability.NoNulls), (ProductId.get, Nullability.Nullable), (ProductId.get, Nullability.NoNulls), (TypoLocalDateTime.get, Nullability.NoNulls), @@ -70,7 +70,7 @@ object BillofmaterialsRow { (TypoLocalDateTime.get, Nullability.NoNulls) ), unsafeGet = (rs: ResultSet, i: Int) => BillofmaterialsRow( - billofmaterialsid = BillofmaterialsId.get.unsafeGetNonNullable(rs, i + 0), + billofmaterialsid = Meta.IntMeta.get.unsafeGetNonNullable(rs, i + 0), productassemblyid = ProductId.get.unsafeGetNullable(rs, i + 1), componentid = ProductId.get.unsafeGetNonNullable(rs, i + 2), startdate = TypoLocalDateTime.get.unsafeGetNonNullable(rs, i + 3), @@ -82,7 +82,7 @@ object BillofmaterialsRow { ) ) implicit lazy val text: Text[BillofmaterialsRow] = Text.instance[BillofmaterialsRow]{ (row, sb) => - BillofmaterialsId.text.unsafeEncode(row.billofmaterialsid, sb) + Text.intInstance.unsafeEncode(row.billofmaterialsid, sb) sb.append(Text.DELIMETER) Text.option(ProductId.text).unsafeEncode(row.productassemblyid, sb) sb.append(Text.DELIMETER) diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala index e4774b4f00..afd0d45d32 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala @@ -38,7 +38,7 @@ case class BillofmaterialsRowUnsaved( bomlevel: TypoShort, /** Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) Primary key for BillOfMaterials records. */ - billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + billofmaterialsid: Defaulted[Int] = Defaulted.UseDefault, /** Default: now() Date the component started being used in the assembly item. Constraint CK_BillOfMaterials_EndDate affecting columns e, n, d, d, a, t, e, ,, , s, t, a, r, t, d, a, t, e: (((enddate > startdate) OR (enddate IS NULL))) */ @@ -51,7 +51,7 @@ case class BillofmaterialsRowUnsaved( /** Default: now() */ modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault ) { - def toRow(billofmaterialsidDefault: => BillofmaterialsId, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = + def toRow(billofmaterialsidDefault: => Int, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = BillofmaterialsRow( productassemblyid = productassemblyid, componentid = componentid, @@ -77,8 +77,8 @@ case class BillofmaterialsRowUnsaved( ) } object BillofmaterialsRowUnsaved { - implicit lazy val decoder: Decoder[BillofmaterialsRowUnsaved] = Decoder.forProduct9[BillofmaterialsRowUnsaved, Option[ProductId], ProductId, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, Defaulted[BillofmaterialsId], Defaulted[TypoLocalDateTime], Defaulted[BigDecimal], Defaulted[TypoLocalDateTime]]("productassemblyid", "componentid", "enddate", "unitmeasurecode", "bomlevel", "billofmaterialsid", "startdate", "perassemblyqty", "modifieddate")(BillofmaterialsRowUnsaved.apply)(Decoder.decodeOption(ProductId.decoder), ProductId.decoder, Decoder.decodeOption(TypoLocalDateTime.decoder), UnitmeasureId.decoder, TypoShort.decoder, Defaulted.decoder(BillofmaterialsId.decoder), Defaulted.decoder(TypoLocalDateTime.decoder), Defaulted.decoder(Decoder.decodeBigDecimal), Defaulted.decoder(TypoLocalDateTime.decoder)) - implicit lazy val encoder: Encoder[BillofmaterialsRowUnsaved] = Encoder.forProduct9[BillofmaterialsRowUnsaved, Option[ProductId], ProductId, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, Defaulted[BillofmaterialsId], Defaulted[TypoLocalDateTime], Defaulted[BigDecimal], Defaulted[TypoLocalDateTime]]("productassemblyid", "componentid", "enddate", "unitmeasurecode", "bomlevel", "billofmaterialsid", "startdate", "perassemblyqty", "modifieddate")(x => (x.productassemblyid, x.componentid, x.enddate, x.unitmeasurecode, x.bomlevel, x.billofmaterialsid, x.startdate, x.perassemblyqty, x.modifieddate))(Encoder.encodeOption(ProductId.encoder), ProductId.encoder, Encoder.encodeOption(TypoLocalDateTime.encoder), UnitmeasureId.encoder, TypoShort.encoder, Defaulted.encoder(BillofmaterialsId.encoder), Defaulted.encoder(TypoLocalDateTime.encoder), Defaulted.encoder(Encoder.encodeBigDecimal), Defaulted.encoder(TypoLocalDateTime.encoder)) + implicit lazy val decoder: Decoder[BillofmaterialsRowUnsaved] = Decoder.forProduct9[BillofmaterialsRowUnsaved, Option[ProductId], ProductId, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, Defaulted[Int], Defaulted[TypoLocalDateTime], Defaulted[BigDecimal], Defaulted[TypoLocalDateTime]]("productassemblyid", "componentid", "enddate", "unitmeasurecode", "bomlevel", "billofmaterialsid", "startdate", "perassemblyqty", "modifieddate")(BillofmaterialsRowUnsaved.apply)(Decoder.decodeOption(ProductId.decoder), ProductId.decoder, Decoder.decodeOption(TypoLocalDateTime.decoder), UnitmeasureId.decoder, TypoShort.decoder, Defaulted.decoder(Decoder.decodeInt), Defaulted.decoder(TypoLocalDateTime.decoder), Defaulted.decoder(Decoder.decodeBigDecimal), Defaulted.decoder(TypoLocalDateTime.decoder)) + implicit lazy val encoder: Encoder[BillofmaterialsRowUnsaved] = Encoder.forProduct9[BillofmaterialsRowUnsaved, Option[ProductId], ProductId, Option[TypoLocalDateTime], UnitmeasureId, TypoShort, Defaulted[Int], Defaulted[TypoLocalDateTime], Defaulted[BigDecimal], Defaulted[TypoLocalDateTime]]("productassemblyid", "componentid", "enddate", "unitmeasurecode", "bomlevel", "billofmaterialsid", "startdate", "perassemblyqty", "modifieddate")(x => (x.productassemblyid, x.componentid, x.enddate, x.unitmeasurecode, x.bomlevel, x.billofmaterialsid, x.startdate, x.perassemblyqty, x.modifieddate))(Encoder.encodeOption(ProductId.encoder), ProductId.encoder, Encoder.encodeOption(TypoLocalDateTime.encoder), UnitmeasureId.encoder, TypoShort.encoder, Defaulted.encoder(Encoder.encodeInt), Defaulted.encoder(TypoLocalDateTime.encoder), Defaulted.encoder(Encoder.encodeBigDecimal), Defaulted.encoder(TypoLocalDateTime.encoder)) implicit lazy val text: Text[BillofmaterialsRowUnsaved] = Text.instance[BillofmaterialsRowUnsaved]{ (row, sb) => Text.option(ProductId.text).unsafeEncode(row.productassemblyid, sb) sb.append(Text.DELIMETER) @@ -90,7 +90,7 @@ object BillofmaterialsRowUnsaved { sb.append(Text.DELIMETER) TypoShort.text.unsafeEncode(row.bomlevel, sb) sb.append(Text.DELIMETER) - Defaulted.text(BillofmaterialsId.text).unsafeEncode(row.billofmaterialsid, sb) + Defaulted.text(Text.intInstance).unsafeEncode(row.billofmaterialsid, sb) sb.append(Text.DELIMETER) Defaulted.text(TypoLocalDateTime.text).unsafeEncode(row.startdate, sb) sb.append(Text.DELIMETER) diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala index 48a762775b..60079addb8 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala @@ -21,7 +21,7 @@ class BillofmaterialsStructure[Row](val prefix: Option[String], val extract: Row extends Relation[BillofmaterialsFields, BillofmaterialsRow, Row] with BillofmaterialsFields[Row] { outer => - override val billofmaterialsid = new IdField[BillofmaterialsId, Row](prefix, "billofmaterialsid", None, Some("int4"))(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) + override val billofmaterialsid = new IdField[Int, Row](prefix, "billofmaterialsid", None, Some("int4"))(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) override val productassemblyid = new OptField[ProductId, Row](prefix, "productassemblyid", None, Some("int4"))(x => extract(x).productassemblyid, (row, value) => merge(row, extract(row).copy(productassemblyid = value))) override val componentid = new Field[ProductId, Row](prefix, "componentid", None, Some("int4"))(x => extract(x).componentid, (row, value) => merge(row, extract(row).copy(componentid = value))) override val startdate = new Field[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), Some("timestamp"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) diff --git a/typo-tester-doobie/generated-and-checked-in/adventureworks/testInsert.scala b/typo-tester-doobie/generated-and-checked-in/adventureworks/testInsert.scala index 5768a426cb..6894191527 100644 --- a/typo-tester-doobie/generated-and-checked-in/adventureworks/testInsert.scala +++ b/typo-tester-doobie/generated-and-checked-in/adventureworks/testInsert.scala @@ -98,7 +98,6 @@ import adventureworks.person.stateprovince.StateprovinceId import adventureworks.person.stateprovince.StateprovinceRepoImpl import adventureworks.person.stateprovince.StateprovinceRow import adventureworks.person.stateprovince.StateprovinceRowUnsaved -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.billofmaterials.BillofmaterialsRepoImpl import adventureworks.production.billofmaterials.BillofmaterialsRow import adventureworks.production.billofmaterials.BillofmaterialsRowUnsaved @@ -434,7 +433,7 @@ class TestInsert(random: Random) { productassemblyid: Option[ProductId] = None, enddate: Option[TypoLocalDateTime] = if (random.nextBoolean()) None else Some(TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)))), bomlevel: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), - billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + billofmaterialsid: Defaulted[Int] = Defaulted.UseDefault, startdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, perassemblyqty: Defaulted[BigDecimal] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala index 17cc54864e..16f06fd6db 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala @@ -9,15 +9,14 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import typo.dsl.SqlExpr.Field import typo.dsl.SqlExpr.OptField trait BomViewFields[Row] { - val id: Field[BillofmaterialsId, Row] - val billofmaterialsid: Field[BillofmaterialsId, Row] + val id: Field[Int, Row] + val billofmaterialsid: Field[Int, Row] val productassemblyid: OptField[ProductId, Row] val componentid: Field[ProductId, Row] val startdate: Field[TypoLocalDateTime, Row] diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala index 27a260492c..697f667f71 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala @@ -9,7 +9,6 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import java.sql.ResultSet @@ -21,9 +20,9 @@ import zio.json.internal.Write case class BomViewRow( /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ - id: BillofmaterialsId, + id: Int, /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ - billofmaterialsid: BillofmaterialsId, + billofmaterialsid: Int, /** Points to [[production.billofmaterials.BillofmaterialsRow.productassemblyid]] */ productassemblyid: Option[ProductId], /** Points to [[production.billofmaterials.BillofmaterialsRow.componentid]] */ @@ -47,8 +46,8 @@ object BomViewRow { override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BomViewRow) = columIndex + 9 -> BomViewRow( - id = BillofmaterialsId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, - billofmaterialsid = BillofmaterialsId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + id = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 0, rs)._2, + billofmaterialsid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, productassemblyid = JdbcDecoder.optionDecoder(ProductId.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, componentid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, @@ -60,8 +59,8 @@ object BomViewRow { ) } implicit lazy val jsonDecoder: JsonDecoder[BomViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => - val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BillofmaterialsId.jsonDecoder)) - val billofmaterialsid = jsonObj.get("billofmaterialsid").toRight("Missing field 'billofmaterialsid'").flatMap(_.as(BillofmaterialsId.jsonDecoder)) + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(JsonDecoder.int)) + val billofmaterialsid = jsonObj.get("billofmaterialsid").toRight("Missing field 'billofmaterialsid'").flatMap(_.as(JsonDecoder.int)) val productassemblyid = jsonObj.get("productassemblyid").fold[Either[String, Option[ProductId]]](Right(None))(_.as(JsonDecoder.option(ProductId.jsonDecoder))) val componentid = jsonObj.get("componentid").toRight("Missing field 'componentid'").flatMap(_.as(ProductId.jsonDecoder)) val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) @@ -78,10 +77,10 @@ object BomViewRow { override def unsafeEncode(a: BomViewRow, indent: Option[Int], out: Write): Unit = { out.write("{") out.write(""""id":""") - BillofmaterialsId.jsonEncoder.unsafeEncode(a.id, indent, out) + JsonEncoder.int.unsafeEncode(a.id, indent, out) out.write(",") out.write(""""billofmaterialsid":""") - BillofmaterialsId.jsonEncoder.unsafeEncode(a.billofmaterialsid, indent, out) + JsonEncoder.int.unsafeEncode(a.billofmaterialsid, indent, out) out.write(",") out.write(""""productassemblyid":""") JsonEncoder.option(ProductId.jsonEncoder).unsafeEncode(a.productassemblyid, indent, out) diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala index 2536eb9061..2402b93eab 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala @@ -9,7 +9,6 @@ package bom import adventureworks.customtypes.TypoLocalDateTime import adventureworks.customtypes.TypoShort -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.product.ProductId import adventureworks.production.unitmeasure.UnitmeasureId import typo.dsl.SqlExpr.Field @@ -21,8 +20,8 @@ class BomViewStructure[Row](val prefix: Option[String], val extract: Row => BomV extends Relation[BomViewFields, BomViewRow, Row] with BomViewFields[Row] { outer => - override val id = new Field[BillofmaterialsId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) - override val billofmaterialsid = new Field[BillofmaterialsId, Row](prefix, "billofmaterialsid", None, None)(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) + override val id = new Field[Int, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val billofmaterialsid = new Field[Int, Row](prefix, "billofmaterialsid", None, None)(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) override val productassemblyid = new OptField[ProductId, Row](prefix, "productassemblyid", None, None)(x => extract(x).productassemblyid, (row, value) => merge(row, extract(row).copy(productassemblyid = value))) override val componentid = new Field[ProductId, Row](prefix, "componentid", None, None)(x => extract(x).componentid, (row, value) => merge(row, extract(row).copy(componentid = value))) override val startdate = new Field[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), None)(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala index d1e5d179dd..5182f7e7aa 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala @@ -16,7 +16,7 @@ import typo.dsl.SqlExpr.IdField import typo.dsl.SqlExpr.OptField trait BillofmaterialsFields[Row] { - val billofmaterialsid: IdField[BillofmaterialsId, Row] + val billofmaterialsid: IdField[Int, Row] val productassemblyid: OptField[ProductId, Row] val componentid: Field[ProductId, Row] val startdate: Field[TypoLocalDateTime, Row] diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala deleted file mode 100644 index 621515b8da..0000000000 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala +++ /dev/null @@ -1,35 +0,0 @@ -/** - * File has been automatically generated by `typo`. - * - * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. - */ -package adventureworks -package production -package billofmaterials - -import adventureworks.Text -import typo.dsl.Bijection -import typo.dsl.ParameterMetaData -import zio.jdbc.JdbcDecoder -import zio.jdbc.JdbcEncoder -import zio.jdbc.SqlFragment.Setter -import zio.json.JsonDecoder -import zio.json.JsonEncoder - -/** Type for the primary key of table `production.billofmaterials` */ -case class BillofmaterialsId(value: Int) extends AnyVal -object BillofmaterialsId { - implicit lazy val arraySetter: Setter[Array[BillofmaterialsId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) - implicit lazy val bijection: Bijection[BillofmaterialsId, Int] = Bijection[BillofmaterialsId, Int](_.value)(BillofmaterialsId.apply) - implicit lazy val jdbcDecoder: JdbcDecoder[BillofmaterialsId] = JdbcDecoder.intDecoder.map(BillofmaterialsId.apply) - implicit lazy val jdbcEncoder: JdbcEncoder[BillofmaterialsId] = JdbcEncoder.intEncoder.contramap(_.value) - implicit lazy val jsonDecoder: JsonDecoder[BillofmaterialsId] = JsonDecoder.int.map(BillofmaterialsId.apply) - implicit lazy val jsonEncoder: JsonEncoder[BillofmaterialsId] = JsonEncoder.int.contramap(_.value) - implicit lazy val ordering: Ordering[BillofmaterialsId] = Ordering.by(_.value) - implicit lazy val parameterMetadata: ParameterMetaData[BillofmaterialsId] = ParameterMetaData.instance[BillofmaterialsId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) - implicit lazy val setter: Setter[BillofmaterialsId] = Setter.intSetter.contramap(_.value) - implicit lazy val text: Text[BillofmaterialsId] = new Text[BillofmaterialsId] { - override def unsafeEncode(v: BillofmaterialsId, sb: StringBuilder) = Text.intInstance.unsafeEncode(v.value, sb) - override def unsafeArrayEncode(v: BillofmaterialsId, sb: StringBuilder) = Text.intInstance.unsafeArrayEncode(v.value, sb) - } -} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala index 7e4fa688ff..8092803814 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala @@ -16,7 +16,7 @@ import zio.jdbc.ZConnection import zio.stream.ZStream trait BillofmaterialsRepo { - def delete(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Boolean] + def delete(billofmaterialsid: Int): ZIO[ZConnection, Throwable, Boolean] def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] def insert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, BillofmaterialsRow] def insertStreaming(unsaved: ZStream[ZConnection, Throwable, BillofmaterialsRow], batchSize: Int): ZIO[ZConnection, Throwable, Long] @@ -25,8 +25,8 @@ trait BillofmaterialsRepo { def insertUnsavedStreaming(unsaved: ZStream[ZConnection, Throwable, BillofmaterialsRowUnsaved], batchSize: Int): ZIO[ZConnection, Throwable, Long] def select: SelectBuilder[BillofmaterialsFields, BillofmaterialsRow] def selectAll: ZStream[ZConnection, Throwable, BillofmaterialsRow] - def selectById(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] - def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): ZStream[ZConnection, Throwable, BillofmaterialsRow] + def selectById(billofmaterialsid: Int): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] + def selectByIds(billofmaterialsids: Array[Int]): ZStream[ZConnection, Throwable, BillofmaterialsRow] def update(row: BillofmaterialsRow): ZIO[ZConnection, Throwable, Boolean] def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] def upsert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, UpdateResult[BillofmaterialsRow]] diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala index 180bd3a863..b99f9812c2 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala @@ -27,15 +27,15 @@ import zio.jdbc.sqlInterpolator import zio.stream.ZStream class BillofmaterialsRepoImpl extends BillofmaterialsRepo { - override def delete(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Boolean] = { - sql"""delete from production.billofmaterials where "billofmaterialsid" = ${Segment.paramSegment(billofmaterialsid)(BillofmaterialsId.setter)}""".delete.map(_ > 0) + override def delete(billofmaterialsid: Int): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.billofmaterials where "billofmaterialsid" = ${Segment.paramSegment(billofmaterialsid)(Setter.intSetter)}""".delete.map(_ > 0) } override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { DeleteBuilder("production.billofmaterials", BillofmaterialsFields) } override def insert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, BillofmaterialsRow] = { sql"""insert into production.billofmaterials("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate") - values (${Segment.paramSegment(unsaved.billofmaterialsid)(BillofmaterialsId.setter)}::int4, ${Segment.paramSegment(unsaved.productassemblyid)(Setter.optionParamSetter(ProductId.setter))}::int4, ${Segment.paramSegment(unsaved.componentid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, ${Segment.paramSegment(unsaved.bomlevel)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.perassemblyqty)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + values (${Segment.paramSegment(unsaved.billofmaterialsid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.productassemblyid)(Setter.optionParamSetter(ProductId.setter))}::int4, ${Segment.paramSegment(unsaved.componentid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, ${Segment.paramSegment(unsaved.bomlevel)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.perassemblyqty)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text """.insertReturning(BillofmaterialsRow.jdbcDecoder).map(_.updatedKeys.head) } @@ -51,7 +51,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { Some((sql""""bomlevel"""", sql"${Segment.paramSegment(unsaved.bomlevel)(TypoShort.setter)}::int2")), unsaved.billofmaterialsid match { case Defaulted.UseDefault => None - case Defaulted.Provided(value) => Some((sql""""billofmaterialsid"""", sql"${Segment.paramSegment(value: BillofmaterialsId)(BillofmaterialsId.setter)}::int4")) + case Defaulted.Provided(value) => Some((sql""""billofmaterialsid"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) }, unsaved.startdate match { case Defaulted.UseDefault => None @@ -89,11 +89,11 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { override def selectAll: ZStream[ZConnection, Throwable, BillofmaterialsRow] = { sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials""".query(BillofmaterialsRow.jdbcDecoder).selectStream } - override def selectById(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] = { - sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ${Segment.paramSegment(billofmaterialsid)(BillofmaterialsId.setter)}""".query(BillofmaterialsRow.jdbcDecoder).selectOne + override def selectById(billofmaterialsid: Int): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] = { + sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ${Segment.paramSegment(billofmaterialsid)(Setter.intSetter)}""".query(BillofmaterialsRow.jdbcDecoder).selectOne } - override def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): ZStream[ZConnection, Throwable, BillofmaterialsRow] = { - sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ANY(${Segment.paramSegment(billofmaterialsids)(BillofmaterialsId.arraySetter)})""".query(BillofmaterialsRow.jdbcDecoder).selectStream + override def selectByIds(billofmaterialsids: Array[Int]): ZStream[ZConnection, Throwable, BillofmaterialsRow] = { + sql"""select "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from production.billofmaterials where "billofmaterialsid" = ANY(${Segment.paramSegment(billofmaterialsids)(adventureworks.IntArraySetter)})""".query(BillofmaterialsRow.jdbcDecoder).selectStream } override def update(row: BillofmaterialsRow): ZIO[ZConnection, Throwable, Boolean] = { val billofmaterialsid = row.billofmaterialsid @@ -106,7 +106,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { "bomlevel" = ${Segment.paramSegment(row.bomlevel)(TypoShort.setter)}::int2, "perassemblyqty" = ${Segment.paramSegment(row.perassemblyqty)(Setter.bigDecimalScalaSetter)}::numeric, "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp - where "billofmaterialsid" = ${Segment.paramSegment(billofmaterialsid)(BillofmaterialsId.setter)}""".update.map(_ > 0) + where "billofmaterialsid" = ${Segment.paramSegment(billofmaterialsid)(Setter.intSetter)}""".update.map(_ > 0) } override def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] = { UpdateBuilder("production.billofmaterials", BillofmaterialsFields, BillofmaterialsRow.jdbcDecoder) @@ -114,7 +114,7 @@ class BillofmaterialsRepoImpl extends BillofmaterialsRepo { override def upsert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, UpdateResult[BillofmaterialsRow]] = { sql"""insert into production.billofmaterials("billofmaterialsid", "productassemblyid", "componentid", "startdate", "enddate", "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate") values ( - ${Segment.paramSegment(unsaved.billofmaterialsid)(BillofmaterialsId.setter)}::int4, + ${Segment.paramSegment(unsaved.billofmaterialsid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.productassemblyid)(Setter.optionParamSetter(ProductId.setter))}::int4, ${Segment.paramSegment(unsaved.componentid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala index 3d693a6a89..4c87b77c5a 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala @@ -24,8 +24,8 @@ import zio.jdbc.ZConnection import zio.stream.ZStream class BillofmaterialsRepoMock(toRow: Function1[BillofmaterialsRowUnsaved, BillofmaterialsRow], - map: scala.collection.mutable.Map[BillofmaterialsId, BillofmaterialsRow] = scala.collection.mutable.Map.empty) extends BillofmaterialsRepo { - override def delete(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Boolean] = { + map: scala.collection.mutable.Map[Int, BillofmaterialsRow] = scala.collection.mutable.Map.empty) extends BillofmaterialsRepo { + override def delete(billofmaterialsid: Int): ZIO[ZConnection, Throwable, Boolean] = { ZIO.succeed(map.remove(billofmaterialsid).isDefined) } override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { @@ -69,10 +69,10 @@ class BillofmaterialsRepoMock(toRow: Function1[BillofmaterialsRowUnsaved, Billof override def selectAll: ZStream[ZConnection, Throwable, BillofmaterialsRow] = { ZStream.fromIterable(map.values) } - override def selectById(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] = { + override def selectById(billofmaterialsid: Int): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] = { ZIO.succeed(map.get(billofmaterialsid)) } - override def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): ZStream[ZConnection, Throwable, BillofmaterialsRow] = { + override def selectByIds(billofmaterialsids: Array[Int]): ZStream[ZConnection, Throwable, BillofmaterialsRow] = { ZStream.fromIterable(billofmaterialsids.flatMap(map.get)) } override def update(row: BillofmaterialsRow): ZIO[ZConnection, Throwable, Boolean] = { diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala index 21f90810e5..b38ebaded6 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala @@ -22,7 +22,7 @@ import zio.json.internal.Write case class BillofmaterialsRow( /** Primary key for BillOfMaterials records. Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) */ - billofmaterialsid: BillofmaterialsId, + billofmaterialsid: Int, /** Parent product identification number. Foreign key to Product.ProductID. Points to [[product.ProductRow.productid]] Constraint CK_BillOfMaterials_BOMLevel affecting columns bomlevel, perassemblyqty, productassemblyid: ((((productassemblyid IS NULL) AND (bomlevel = 0) AND (perassemblyqty = 1.00)) OR ((productassemblyid IS NOT NULL) AND (bomlevel >= 1)))) @@ -59,7 +59,7 @@ object BillofmaterialsRow { override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BillofmaterialsRow) = columIndex + 8 -> BillofmaterialsRow( - billofmaterialsid = BillofmaterialsId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + billofmaterialsid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 0, rs)._2, productassemblyid = JdbcDecoder.optionDecoder(ProductId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, componentid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, @@ -71,7 +71,7 @@ object BillofmaterialsRow { ) } implicit lazy val jsonDecoder: JsonDecoder[BillofmaterialsRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => - val billofmaterialsid = jsonObj.get("billofmaterialsid").toRight("Missing field 'billofmaterialsid'").flatMap(_.as(BillofmaterialsId.jsonDecoder)) + val billofmaterialsid = jsonObj.get("billofmaterialsid").toRight("Missing field 'billofmaterialsid'").flatMap(_.as(JsonDecoder.int)) val productassemblyid = jsonObj.get("productassemblyid").fold[Either[String, Option[ProductId]]](Right(None))(_.as(JsonDecoder.option(ProductId.jsonDecoder))) val componentid = jsonObj.get("componentid").toRight("Missing field 'componentid'").flatMap(_.as(ProductId.jsonDecoder)) val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) @@ -88,7 +88,7 @@ object BillofmaterialsRow { override def unsafeEncode(a: BillofmaterialsRow, indent: Option[Int], out: Write): Unit = { out.write("{") out.write(""""billofmaterialsid":""") - BillofmaterialsId.jsonEncoder.unsafeEncode(a.billofmaterialsid, indent, out) + JsonEncoder.int.unsafeEncode(a.billofmaterialsid, indent, out) out.write(",") out.write(""""productassemblyid":""") JsonEncoder.option(ProductId.jsonEncoder).unsafeEncode(a.productassemblyid, indent, out) @@ -117,7 +117,7 @@ object BillofmaterialsRow { } } implicit lazy val text: Text[BillofmaterialsRow] = Text.instance[BillofmaterialsRow]{ (row, sb) => - BillofmaterialsId.text.unsafeEncode(row.billofmaterialsid, sb) + Text.intInstance.unsafeEncode(row.billofmaterialsid, sb) sb.append(Text.DELIMETER) Text.option(ProductId.text).unsafeEncode(row.productassemblyid, sb) sb.append(Text.DELIMETER) diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala index d1fea6a6a2..861f4edfc6 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala @@ -40,7 +40,7 @@ case class BillofmaterialsRowUnsaved( bomlevel: TypoShort, /** Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) Primary key for BillOfMaterials records. */ - billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + billofmaterialsid: Defaulted[Int] = Defaulted.UseDefault, /** Default: now() Date the component started being used in the assembly item. Constraint CK_BillOfMaterials_EndDate affecting columns e, n, d, d, a, t, e, ,, , s, t, a, r, t, d, a, t, e: (((enddate > startdate) OR (enddate IS NULL))) */ @@ -53,7 +53,7 @@ case class BillofmaterialsRowUnsaved( /** Default: now() */ modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault ) { - def toRow(billofmaterialsidDefault: => BillofmaterialsId, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = + def toRow(billofmaterialsidDefault: => Int, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = BillofmaterialsRow( productassemblyid = productassemblyid, componentid = componentid, @@ -85,7 +85,7 @@ object BillofmaterialsRowUnsaved { val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) val bomlevel = jsonObj.get("bomlevel").toRight("Missing field 'bomlevel'").flatMap(_.as(TypoShort.jsonDecoder)) - val billofmaterialsid = jsonObj.get("billofmaterialsid").toRight("Missing field 'billofmaterialsid'").flatMap(_.as(Defaulted.jsonDecoder(BillofmaterialsId.jsonDecoder))) + val billofmaterialsid = jsonObj.get("billofmaterialsid").toRight("Missing field 'billofmaterialsid'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) val perassemblyqty = jsonObj.get("perassemblyqty").toRight("Missing field 'perassemblyqty'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) @@ -112,7 +112,7 @@ object BillofmaterialsRowUnsaved { TypoShort.jsonEncoder.unsafeEncode(a.bomlevel, indent, out) out.write(",") out.write(""""billofmaterialsid":""") - Defaulted.jsonEncoder(BillofmaterialsId.jsonEncoder).unsafeEncode(a.billofmaterialsid, indent, out) + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.billofmaterialsid, indent, out) out.write(",") out.write(""""startdate":""") Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.startdate, indent, out) @@ -136,7 +136,7 @@ object BillofmaterialsRowUnsaved { sb.append(Text.DELIMETER) TypoShort.text.unsafeEncode(row.bomlevel, sb) sb.append(Text.DELIMETER) - Defaulted.text(BillofmaterialsId.text).unsafeEncode(row.billofmaterialsid, sb) + Defaulted.text(Text.intInstance).unsafeEncode(row.billofmaterialsid, sb) sb.append(Text.DELIMETER) Defaulted.text(TypoLocalDateTime.text).unsafeEncode(row.startdate, sb) sb.append(Text.DELIMETER) diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala index 48a762775b..60079addb8 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala @@ -21,7 +21,7 @@ class BillofmaterialsStructure[Row](val prefix: Option[String], val extract: Row extends Relation[BillofmaterialsFields, BillofmaterialsRow, Row] with BillofmaterialsFields[Row] { outer => - override val billofmaterialsid = new IdField[BillofmaterialsId, Row](prefix, "billofmaterialsid", None, Some("int4"))(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) + override val billofmaterialsid = new IdField[Int, Row](prefix, "billofmaterialsid", None, Some("int4"))(x => extract(x).billofmaterialsid, (row, value) => merge(row, extract(row).copy(billofmaterialsid = value))) override val productassemblyid = new OptField[ProductId, Row](prefix, "productassemblyid", None, Some("int4"))(x => extract(x).productassemblyid, (row, value) => merge(row, extract(row).copy(productassemblyid = value))) override val componentid = new Field[ProductId, Row](prefix, "componentid", None, Some("int4"))(x => extract(x).componentid, (row, value) => merge(row, extract(row).copy(componentid = value))) override val startdate = new Field[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), Some("timestamp"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/testInsert.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/testInsert.scala index a1c7dcd7b1..ce08bf8d2b 100644 --- a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/testInsert.scala +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/testInsert.scala @@ -98,7 +98,6 @@ import adventureworks.person.stateprovince.StateprovinceId import adventureworks.person.stateprovince.StateprovinceRepoImpl import adventureworks.person.stateprovince.StateprovinceRow import adventureworks.person.stateprovince.StateprovinceRowUnsaved -import adventureworks.production.billofmaterials.BillofmaterialsId import adventureworks.production.billofmaterials.BillofmaterialsRepoImpl import adventureworks.production.billofmaterials.BillofmaterialsRow import adventureworks.production.billofmaterials.BillofmaterialsRowUnsaved @@ -435,7 +434,7 @@ class TestInsert(random: Random) { productassemblyid: Option[ProductId] = None, enddate: Option[TypoLocalDateTime] = if (random.nextBoolean()) None else Some(TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)))), bomlevel: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), - billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + billofmaterialsid: Defaulted[Int] = Defaulted.UseDefault, startdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, perassemblyqty: Defaulted[BigDecimal] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault diff --git a/typo/src/scala/typo/Options.scala b/typo/src/scala/typo/Options.scala index 64175bd77d..0b57bc642e 100644 --- a/typo/src/scala/typo/Options.scala +++ b/typo/src/scala/typo/Options.scala @@ -11,6 +11,7 @@ case class Options( typeOverride: TypeOverride = TypeOverride.Empty, nullabilityOverride: NullabilityOverride = NullabilityOverride.Empty, generateMockRepos: Selector = Selector.All, + enablePrimaryKeyType: Selector = Selector.All, enableFieldValue: Selector = Selector.None, enableTestInserts: Selector = Selector.None, readonlyRepo: Selector = Selector.None, diff --git a/typo/src/scala/typo/internal/ComputedTable.scala b/typo/src/scala/typo/internal/ComputedTable.scala index 061dd6f46e..1260bc1cb9 100644 --- a/typo/src/scala/typo/internal/ComputedTable.scala +++ b/typo/src/scala/typo/internal/ComputedTable.scala @@ -53,6 +53,8 @@ case class ComputedTable( case None => if (sc.Type.containsUserDefined(underlying)) Some(IdComputed.UnaryUserSpecified(col, underlying)) + else if (!options.enablePrimaryKeyType.include(dbTable.name)) + Some(IdComputed.UnaryNoIdType(col, underlying)) else Some(IdComputed.UnaryNormal(col, tpe)) diff --git a/typo/src/scala/typo/internal/IdComputed.scala b/typo/src/scala/typo/internal/IdComputed.scala index 2aaf1996dc..01806cdb1c 100644 --- a/typo/src/scala/typo/internal/IdComputed.scala +++ b/typo/src/scala/typo/internal/IdComputed.scala @@ -21,11 +21,16 @@ object IdComputed { def underlying: sc.Type = col.tpe } - // normal generated code for a normal single-column id + // normal generated code for a normal single-column id, we won't generate extra code for this usage of it case class UnaryInherited(col: ComputedColumn, tpe: sc.Type) extends Unary { def underlying: sc.Type = col.tpe } + // // user specified they don't want a primary key type for this + case class UnaryNoIdType(col: ComputedColumn, tpe: sc.Type) extends Unary { + def underlying: sc.Type = col.tpe + } + // if user supplied a type override for an id column case class UnaryUserSpecified(col: ComputedColumn, tpe: sc.Type) extends Unary { override def paramName: sc.Ident = col.name diff --git a/typo/src/scala/typo/internal/InternalOptions.scala b/typo/src/scala/typo/internal/InternalOptions.scala index c065b89958..2902ded95c 100644 --- a/typo/src/scala/typo/internal/InternalOptions.scala +++ b/typo/src/scala/typo/internal/InternalOptions.scala @@ -12,6 +12,7 @@ case class InternalOptions( enableTestInserts: Selector, fileHeader: String, generateMockRepos: Selector, + enablePrimaryKeyType: Selector, jsonLibs: List[JsonLib], keepDependencies: Boolean, logger: TypoLogger, diff --git a/typo/src/scala/typo/internal/codegen/FilesTable.scala b/typo/src/scala/typo/internal/codegen/FilesTable.scala index 08f869515d..1a864aa111 100644 --- a/typo/src/scala/typo/internal/codegen/FilesTable.scala +++ b/typo/src/scala/typo/internal/codegen/FilesTable.scala @@ -132,9 +132,7 @@ case class FilesTable(table: ComputedTable, options: InternalOptions, genOrderin ) ) - case _: IdComputed.UnaryUserSpecified => - None - case _: IdComputed.UnaryInherited => + case _: IdComputed.UnaryUserSpecified | _: IdComputed.UnaryNoIdType | _: IdComputed.UnaryInherited => None case id @ IdComputed.Composite(cols, qident, _) => val comments = scaladoc(s"Type for the composite primary key of table `${table.dbTable.name.value}`")(Nil) diff --git a/typo/src/scala/typo/internal/generate.scala b/typo/src/scala/typo/internal/generate.scala index cf116bbd37..3d1bd456d9 100644 --- a/typo/src/scala/typo/internal/generate.scala +++ b/typo/src/scala/typo/internal/generate.scala @@ -35,6 +35,7 @@ object generate { enableTestInserts = publicOptions.enableTestInserts, fileHeader = publicOptions.fileHeader, generateMockRepos = publicOptions.generateMockRepos, + enablePrimaryKeyType = publicOptions.enablePrimaryKeyType, jsonLibs = publicOptions.jsonLibs.map { case JsonLibName.Circe => JsonLibCirce(pkg, default, publicOptions.inlineImplicits) case JsonLibName.PlayJson => JsonLibPlay(pkg, default, publicOptions.inlineImplicits)